I have a JSP that gets a ResultSet object from a database, then it shows the values of the database in a table with checkboxes ready for selection, the only thing im having problems is getting those checked box values so that I can send them to my servlet then to another page showing a table of the selected items.
I've check everything that I can and I still cant find the answer.
Here's what i got: JSP for viewing data:
<%
ResultSet results = (ResultSet)request.getAttribute("results");
int countme=0;
int numb=1;
while (results.next()) {
++countme;
numb=countme;
%>
<tr>
<td><input type ="checkbox" id="cb_<%=(numb)%>"
class="cbgroup"
value="<%out.println(results.getString("ANI_TITLE"));%>"
name="cbg"
/>
</td>
<td><%=results.getString("ANI_TITLE") %></td>
<td><%=results.getString("ANI_STUDIO") %></td>
<td><%=results.getString("ANI_EPI") %></td>
</tr>
<% }
%>
Then, once checked, you click the button that goes to this Servlet part:
else if (btn.equals("Continue")){
token="delcont";
String[] vals1=request.getParameterValues("cbg");
}
request.setAttribute("vals1", vals1);
request.setAttribute("token", token);
RequestDispatcher dispatch = request.getRequestDispatcher("deletechecked.jsp");
dispatch.forward(request, response);
}
and then the servlet sends it to this JSP for viewing the checked values in a table:
<h2>Are you sure to delete these?</h2>
<table border="1" align="center">
<tr>
<th>Anime Title</th>
<%--<th>Anime Studio</th>
<th>No. of Episodes</th>--%>
</tr>
<%
String[] values = request.getParameterValues("cbg");
String holder="";
for(int i=0;i < values.length;i++){
%>
<tr><td><%=values%></td></tr>
<%
}
%>
This code outputs a Hashcode of the array. We dont want that.
Hope you can help me. Thanks.
UPDATE: I got it working, but it prints the hashcode instead of the string. *Updated the Code above. It prints [Ljava.lang.String;@29cfc19f] as the array element.