我如何在JSP中解决此代码?

时间:2015-08-19 05:24:45

标签: java jsp

我在显示输出时遇到问题..如果我检查一些复选框并单击提交按钮..它应显示我已检查的数字,但它只显示第一个数字。

    <form name="input" action = "index.jsp" method="get">

    <table border ="1"><% 
    String [] list = new String[6];
    String cbvalues ;
    int num = 1;
    int x = 1;    
        for(int i = 1;i<8;i++){
            %><tr><%
            for(int j = 1;j<9;j++){
                %><td><%
                out.println(num);

                num++;
                %><input type = "checkbox" name="lotto" value="${x = x+1}"><%
                if(num==56){
                    break;
                }

                %></td><%
            } 
        }            
                %></tr>                    
    </table>
        <input type ="submit" value ="Submit">
               <% 
        for(int i = 0;i<6;i++){
        cbvalues = request.getParameter("lotto");

        list[i] = cbvalues;
        out.println(list[i]);
        }

                %>
    </form>

2 个答案:

答案 0 :(得分:1)

由于在JSP页面中你不能调用getParameterValues("");方法,它会返回一个复选框值。所以你可以使用像

String lotto[]= request.getParameterValues("lotto");
if (lotto != null && lotto.length != 0) {
out.println("You have selected: ");
for (int i = 0; i < lotto.length; i++) {
out.println(lotto[i]); 
}

答案 1 :(得分:0)

使用此

String lotto[]= request.getParameterValues("lotto");
if(lotto != null)
{
    for(int i=0; i<lotto.length; i++)
    {
        out.print(lotto[i]);
    }
}
相关问题