我想从jsp checkbox
获取值,但它总是返回null
。我有以下代码来设置从checkbox
...
ArrayList
<%
Shopping shop = new Shopping();
ArrayList<String> getProd = shop.getProducts();
for (int i = 0; i < getProd.size(); i++) {
%>
<tr>
<td><input type="checkbox" name="selectBox" value=<%=getProd.get(i)%>><%=getProd.get(i)%></td>
<td><input type="text" name="qty" size="4"></td>
</tr>
<%
}
%>
当我尝试按照以下方式调用此类时,它始终返回null
。您能否告诉我从这些checkboxes
获取价值的正确方法?
<%
String[] selected = request.getParameterValues("selectBox");
out.println("Selected: " + selected);
if (selected != null && selected.length != 0) {
out.println("You have selected: ");
for (int i = 0; i < selected.length; i++) {
out.println(selected[i]);
}
}
%>