我在显示输出时遇到问题..如果我选中一些复选框并单击提交按钮..它应该显示我已检查的数字,但它只显示第一个数字。
<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>
最佳答案
由于在 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]);
}
关于java - 我该如何解决JSP中的这段代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32087136/