从JSP页面获取复选框值 - 返回null

时间:2012-06-18 20:28:27

标签: java jsp checkbox

我想从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]);
    }
}
%>

0 个答案:

没有答案