我是初学者。我想将一组复选框值从一个 JSP 页面传递到另一个页面。获取数据的页面是
<%
ResultSet rs=s.notapprovedqns();
%>
<%
while(rs.next())
{ %>
<tr><td><input name="qns[]" type="checkbox" value="<% out.println(rs.getInt("question_id")); %>" /></td><td><center><%=rs.getString("question_id") %></center></td><td><%=rs.getString("question") %></td></td></tr>
<%
}
%>
如何在另一个页面的 JSP 中接收复选框值。我试过下面的代码,但它不能正常工作
String[] h=null;
h=request.getParameterValues("qns[]");
但是它传递了值
[Ljava.lang.String;@a0a595
请有人帮我解决这个问题。
最佳答案
您可以按如下方式使用它。 在表单中
<form method="post" action="process.jsp">
<input type="checkbox" name="list" value="value1">
<input type="checkbox" name="list" value="value2">
<input type="checkbox" name="list" value="value3">
</form>
在process.jsp中
String[] ids=request.getParameterValues("list");
// this will get array of values of all checked checkboxes
for(String id:ids){
// do something with id, this is checkbox value
}
关于java - 如何将一组复选框值从一个 JSP 页面传递到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18492203/