代码如下:
<select name="merTransactionTypeId" class="cbox" multiple>
<!--
<option value="0" <%=request.getParameter("merTransactionTypeId")!=null?"0".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>All</option>
-->
<option value="2" <%=request.getParameter("merTransactionTypeId")!=null?"2".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>Reload</option>
<option value="1" <%=request.getParameter("merTransactionTypeId")!=null?"1".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>Sale</option>
<option value="5" <%=request.getParameter("merTransactionTypeId")!=null?"5".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>CCMS_Recharge</option>
<option value="6" <%=request.getParameter("merTransactionTypeId")!=null?"6".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>Loyalty_Award</option>
<option value="7" <%=request.getParameter("merTransactionTypeId")!=null?"7".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>Loyalty_Redeem</option>
<option value="16" <%=request.getParameter("merTransactionTypeId")!=null?"16".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>FCC_Reload</option>
<option value="11" <%=request.getParameter("merTransactionTypeId")!=null?"11".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>Tracking</option>
<option value="12" <%=request.getParameter("merTransactionTypeId")!=null?"12".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>Fund_Transfer_From_Card</option>
</select>
我正在尝试使用 scriplet 中的代码从下拉列表中检索值
<% String[] selectedTransactionTypes = request.getParameterValues("merTransactionTypeId"); %>
...但它返回 null。请帮帮我。
最佳答案
显然列表框没有包含在相同的 <form>
中,或者甚至没有办法 <form>
,或者您可能在错误的时刻尝试访问它(例如在表单提交之前),或者参数名称可能存在拼写错误(使用 getParameterNames()
查看全部参数)。
也就是说,我强烈建议您将老式的 scriptlet 放在一边,并继续使用 servlet 类来预处理和后处理请求,并使用 taglibs/EL 来控制 JSP 中的流程和访问数据。它将使您的代码更加简洁。
关于java - 如何在java代码中从<select multiple>检索多个选定的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1995793/