土士二干
2021-10-17 20:48
采纳率: 100%
浏览 13
已结题

Servlet接收不到jsp页面里的select列表中选中的值

我jsp页面中下拉列表中option嵌套了<c:if>,
页面中能显示,但是Servlet中接收的值始终是null,
找问题找了很久感觉应该是传参出了问题,
但是不知道具体出在哪
感激不尽

jsp中:

<form method="get" action="SelectBillServlet">
               <input name="method" value="query" class="input-text" type="hidden">
               <span>商品名称:</span>
               <input name="queryProductName" type="text" value="${queryProductName }">

               <span>供应商:</span>
               <select name="queryProviderId">
                   <c:if test="${requestScope.providerList != null }">
                       <option value="0">--请选择--</option>
                       <c:forEach var="provider" items="${requestScope.providerList}">
                           <option <c:if test="${provider.id == queryProviderId }">selected="selected"</c:if>
                                   value="${provider.id}">${provider.proName}</option>
                       </c:forEach>
                   </c:if>
               </select>
               <span>是否付款:</span>
               <select name="queryIsPayment">
                   <option value="0">--请选择--</option>
                   <option value="1" ${queryIsPayment == 1 ? "selected=\"selected\"":"" }>未付款</option>
                   <option value="2" ${queryIsPayment == 2 ? "selected=\"selected\"":"" }>已付款</option>
               </select>

               <input    value="查 询" type="submit" id="searchbutton">
               <a href="${pageContext.request.contextPath }/jsp/billadd.jsp">添加订单</a>
           </form>

Servlet中:

    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获得供应商集合
        ProviderService providerService = new ProviderServiceImpl();
        List<Provider> providerList = providerService.getProviders();
        req.setAttribute("providerList",providerList);
        System.out.println(providerList.size());
        //获得商品订单集合
        String productName = req.getParameter("queryProductName");
        Integer providerId = Integer.getInteger(req.getParameter("queryProviderId"));
        Integer isPayment = Integer.getInteger(req.getParameter("queryIsPayment"));
        System.out.println("商品名称:" + productName + "\t供应商:" + providerId + "\t是否付款:" + isPayment);
        BillService bs = new BilServiceImpl();
        List<Bill> bis = bs.selectBill(productName,providerId,isPayment);
        req.setAttribute("bis",bis);
//        req.setAttribute("queryProductName", productName);
//        req.setAttribute("queryProviderId", providerId);
//        req.setAttribute("queryIsPayment", isPayment);
        req.getRequestDispatcher("jsp/billlist.jsp").forward(req,resp);
    }
  • 好问题 提建议
  • 收藏

1条回答 默认 最新

  • CSDN专家-sinjack 2021-10-17 20:53
    已采纳

    先看下请求有没有传递参数值,以及servlet 获取的属性和jsp标签属性name值是否一致。

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题