<%@ page contentType="text/html; charset=UTF-8" %>
<%
String[] s = request.getParameterValues("chk");
if(s != null && s.length > 0){
for(int i = 0; i < s.length; i++){
out.println(s[i]);
}
}
%>
<html>
<head>
</head>
<body bgcolor="#ffffc0">
<form method="POST" action="case_save_test.jsp" name="frm">
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="submit" value="h" />
</form>
</body>
</html>
我想得到这10个chk的value值,如果被选中,其值为1,否则为0
例:第一个和第二个被选中,得到s[0]=1 s[1]=1 s[2...9]=0
不用js,因为我想将数组直接传到另一个bean里
现在的难题:我只得到了被选中的值,而且不知道是第几个,假如第三个选中,得到S的长度是1,s[0]=1,其他的就没了,求大家帮忙
<%
String[] s = request.getParameterValues("chk");
if(s != null && s.length > 0){
for(int i = 0; i < s.length; i++){
out.println(s[i]);
}
}
%>
<html>
<head>
</head>
<body bgcolor="#ffffc0">
<form method="POST" action="case_save_test.jsp" name="frm">
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="submit" value="h" />
</form>
</body>
</html>
我想得到这10个chk的value值,如果被选中,其值为1,否则为0
例:第一个和第二个被选中,得到s[0]=1 s[1]=1 s[2...9]=0
不用js,因为我想将数组直接传到另一个bean里
现在的难题:我只得到了被选中的值,而且不知道是第几个,假如第三个选中,得到S的长度是1,s[0]=1,其他的就没了,求大家帮忙
<input type="checkbox" name="chk" value="2"/>2
<input type="checkbox" name="chk" value="3"/>3
<input type="checkbox" name="chk" value="4"/>4
<input type="checkbox" name="chk" value="5"/>5
<input type="checkbox" name="chk" value="6"/>6
<input type="checkbox" name="chk" value="7"/>7
<input type="checkbox" name="chk" value="8"/>8
<input type="checkbox" name="chk" value="9"/>9
<input type="checkbox" name="chk" value="10"/>10把每个值改成不一样不就可以了
<%
String[] s = request.getParameterValues("chk");//数组存放结果
int result[10];
for(int j=0;j<10;j++)
{
result[j]=0;
}if(s != null && s.length > 0){
for(int i = 0; i < s.length; i++){
int id=IntergeInteger.parseInt(s[i]);
result[id-1]=1;
}for(int j=0;j<10;j++)
{
if(result[j]==0)
{
out.println("第%d个元素没有被选中",j);
}
else
{
out.println("第%d个元素被选中",j);
}}}
%>
<html>
<head>
</head>
<body bgcolor="#ffffc0">
<form method="POST" action="case_save_test.jsp" name="frm">
<input type="checkbox" name="chk" value="1"/>1
<input type="checkbox" name="chk" value="2"/>2
<input type="checkbox" name="chk" value="3"/>3
<input type="checkbox" name="chk" value="4"/>4
<input type="checkbox" name="chk" value="5"/>5
<input type="checkbox" name="chk" value="6"/>6
<input type="checkbox" name="chk" value="7"/>7
<input type="checkbox" name="chk" value="8"/>8
<input type="checkbox" name="chk" value="9"/>9
<input type="checkbox" name="chk" value="10"/>10
<input type="submit" value="h" />
</form>
</body>
</html>应该可以了,没有作测试,可能有细节上的错误