1

我的 JSP 页面中有 2 个或更多下拉列表...现在在我的 servlet 中,我想将两个下拉列表中选定项目的两个值传递给数据库,并将该值查询到数据库。我不想对所有可能的组合有这么多的方法,并将所有这些组合归为一类。现在我怎样才能在 ddl 中传递所选项目的两个值?

这是我的尝试

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        int SelectedOrg;
        int SelectedSec;
        String FilterByOrg = req.getParameter("OrgFilter");
        String FilterBySec = req.getParameter("SectorFilter");
        if (!"11".equals(FilterByOrg) && !"11".equals(FilterBySec))
        {       
                SelectedOrg = Integer.parseInt(req.getParameter("OrgFilter"));
                SelectedSec = Integer.parseInt(req.getParameter("SectorFilter"));
                List<OrganizationItems> orgItems = new ViewAllOrganizations().findEMSOnly(SelectedOrg, SelectedSec);
                req.setAttribute("orgItems", orgItems);
                jsp.forward(req, resp);
        }
        else
        {
            List<OrganizationItems> orgItems = new ViewAllOrganizations().findAll();
            req.setAttribute("orgItems", orgItems);
            jsp.forward(req, resp);
        }
    }

这是我的 JSP 页面

 <form method="GET">
                            <div>
                                <span>Organization: </span> <select name="OrgFilter">
                                <option value="11">Organization Type</option>
                                <option value="22">All</option>
                                    <option value="1">Emergency Medical Service</option>
                                    <option value="3">Fire Suppression Group</option>
                                    <option value="4">Medical Facilities</option>
                                </select>
                            </div>
                            <div>
                                <span>Sector: </span> <select name="SectorFilter" onchange="submit()">
                                <option value="11">Sector Type</option>
                                    <option value="22">All</option>
                                    <option value="1">NA</option>
                                    <option value="2">Government</option>
                                    <option value="3">Private</option>
                                    <option value="4">Volunteer</option>
                                    <option value="5">Corporate/Industrial</option>
                                </select>
                            </div>
                            </form>

在此之后,我的表格位于显示结果的表单标记下方

4

0 回答 0