在Java、JavaScript和HTML中使用AppEngine时如何获取SelectBox的值

在Java、JavaScript和HTML中使用AppEngine时如何获取SelectBox的值,java,javascript,html,google-app-engine,Java,Javascript,Html,Google App Engine,我试图创建一种过滤存储在数据存储中的数据的方法。我使用的方法是HTML、Javascript和Javaservlet的混合。生成一个表单,允许将输入到Web应用程序的数据发送到Javaservlet。然后Servlet执行所需的操作,并将用户发送回包含更新数据的页面。我的问题是,我必须在此表单中使用一个选择框,该框允许用户选择他们希望筛选的主题,例如标题、作者。按下提交按钮时,选择框的值不会作为参数发送。这意味着出现错误500,因为没有足够的参数来执行该功能。我需要:- 获取SelectBox的

我试图创建一种过滤存储在数据存储中的数据的方法。我使用的方法是HTML、Javascript和Javaservlet的混合。生成一个表单,允许将输入到Web应用程序的数据发送到Javaservlet。然后Servlet执行所需的操作,并将用户发送回包含更新数据的页面。我的问题是,我必须在此表单中使用一个选择框,该框允许用户选择他们希望筛选的主题,例如标题、作者。按下提交按钮时,选择框的值不会作为参数发送。这意味着出现错误500,因为没有足够的参数来执行该功能。我需要:-

  • 获取SelectBox的值

  • 将其与文本字段中的参数值一起传递给函数。(几乎完成)

  • 将idvBook的值设置为等于发送回Webb应用程序的列表

  • 首先,这是我使用SelectBox、TextInput和ButonInput创建表单的方式:-

    <div class="headline">Filter the DataStore</div>
        <div class="info">To view individual records, select the attribute 
        you'd like to filter by and enter the value you'd like to find. Click 
        the button to generate the table based on your search criteria.</div>
        <script type="text/javascript">
             function filter(){
                 document.filterBooks.action="/get";
                 var idvBook = document.filterBooks.submit();
             }
        </script>
        <form name="filterBooks">
            <table>
                <tr>
                    <td valign="top"><label for="attribute">Attribute</label></td>
                    <td>
                        <select id="attributeSelect">
                            <option value="void">Select Attribute</option>
                            <option value="id">ID</option>
                            <option value="title">Title</option>
                            <option value="author">Author</option>
                            <option value="publisher">Publisher</option>
                        </select>
    
                    </td>
    
                </tr>
                <tr>
                    <td valign="top"><label for="value">Value</label></td>
                    <td><input type="text" name="value" id="value"></input></td>
                </tr>
                <tr>
                    <td colspan="2" align="right"><input type="submit" value="Filter" onclick="filter()"></td>
                </tr>
            </table>
        </form>
        <table>
            <tr>
                <th>Book ID</th>
                <th>Title</th>
                <th>Description</th>
                <th>Author</th>
                <th>Publisher</th>
                <th>Publish Date</th>
                <th>Remove Book</th>
            </tr>
            <%
                for (Book book : idvBook) {
            %>
            <tr>
                <td><%=book.getId()%></td>
                <td><%=book.getTitle()%></td>
                <td><%=book.getDescription()%></td>
                <td><%=book.getAuthor()%></td>
                <td><%=book.getPublisher()%></td>
                <td><%=book.getPublishDate()%></td>
                <td><a class="done" href="/done?id=<%=book.getId()%>">Remove</a></td>
            </tr>
            <%
                }
            %>
        </table>
    </div>
    
    您可以看到另一个函数在这里运行。此函数如下所示:-

    public List<Book> getBooks(String attribute, String param) {
        EntityManager em = EMFService.get().createEntityManager();
       Query q = null;
    
        if(attribute.equals("id"))
        {
            q = em.createQuery("select b from Book b where b.id = :id");
            q.setParameter("id", param);
        }
        else if(attribute.equals("title"))
        {
            q = em.createQuery("select b from Book b where b.title = :title");
            q.setParameter("title", param);
        }
        else if(attribute.equals("author"))
        {
            q = em.createQuery("select b from Book b where b.author = :author");
            q.setParameter("author", param);
        }
        else if(attribute.equals("publisher"))
        {
            q = em.createQuery("select b from Book b where b.publisher = :publisher");
            q.setParameter("publisher", param);
        }
        List<Book> books = q.getResultList();
        return books;
    }
    
    公共列表getbook(字符串属性,字符串参数){
    EntityManager em=EMFService.get().createEntityManager();
    查询q=null;
    if(attribute.equals(“id”))
    {
    q=em.createQuery(“从书b中选择b,其中b.id=:id”);
    q、 设置参数(“id”,参数);
    }
    else if(attribute.equals(“title”))
    {
    q=em.createQuery(“从书b中选择b,其中b.title=:title”);
    q、 设置参数(“标题”,参数);
    }
    else if(attribute.equals(“author”))
    {
    q=em.createQuery(“从书b中选择b,其中b.author=:author”);
    q、 setParameter(“作者”,参数);
    }
    else if(attribute.equals(“publisher”))
    {
    q=em.createQuery(“从书b中选择b,其中b.publisher=:publisher”);
    q、 setParameter(“发布者”,参数);
    }
    List books=q.getResultList();
    还书;
    }
    
    如何获取它,以便获取SelectBox的值,运行函数并将其结果设置为等于idvBook

    编辑-------------------------------------------------------------------------------------------------

    我会简化事情。我需要这个标签:-

    List idvBook=new ArrayList();
    idvBook=dao.getBook(“选择框中的值”、“文本输入中的值”);
    
    您的选择框没有名称属性,因此其值不会随表单数据一起发送

    public List<Book> getBooks(String attribute, String param) {
        EntityManager em = EMFService.get().createEntityManager();
       Query q = null;
    
        if(attribute.equals("id"))
        {
            q = em.createQuery("select b from Book b where b.id = :id");
            q.setParameter("id", param);
        }
        else if(attribute.equals("title"))
        {
            q = em.createQuery("select b from Book b where b.title = :title");
            q.setParameter("title", param);
        }
        else if(attribute.equals("author"))
        {
            q = em.createQuery("select b from Book b where b.author = :author");
            q.setParameter("author", param);
        }
        else if(attribute.equals("publisher"))
        {
            q = em.createQuery("select b from Book b where b.publisher = :publisher");
            q.setParameter("publisher", param);
        }
        List<Book> books = q.getResultList();
        return books;
    }
    
    List<Book> idvBook = new ArrayList<Book>();
    idvBook = dao.getBook("Value in SelectBox","Value in TextInput");