Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass an array of checkbox value From one JSP page to another

I am a beginner. I want to pass an array of check box values from one JSP page to another. The page getting data is

<%
     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>
     <% 
        }
      %>

How can i receive check box values in JSP another page. I have tried the following code but its not working properly

String[] h=null;
h=request.getParameterValues("qns[]");

But its passing the value

[Ljava.lang.String;@a0a595 

Please somebody help me to solve this problem.

like image 922
Salini L Avatar asked Mar 23 '23 14:03

Salini L


1 Answers

You Can use it as follows. in Form

<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>

In 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
    }
like image 90
Mazhar Avatar answered Mar 25 '23 03:03

Mazhar