JavaServer Pages (JSP) and JSTL - Dynamic creation & selction of rows

Hi,

I am using JSP to dynamically populate & display the database records in a HTML table.

I want to select a particular data row using a checkbox. I can create checkbox like below

<% while(resultset.next()){ %>

<TR>

<TD> <input name="ck1" type="checkbox" value="" /></td>

<TD>

<%= resultset.getString(1) %>
</td> <TD>
<%= resultset.getString(2) %>
</TD>

</TR>

<% } %>

but the probelm is that, though multiple checkboxes appear on screen with each row, actually it's only one with "ck1" name.

How can i make selection of row using checkbox?

Can someone help me with this issue?

Thanks

[811 byte] By [csp_javaa] at [2007-11-26 23:17:40]
# 1

<% int row = 0;

while(resultset.next()){ %>

<TR>

<TD> <input name="ck1" type="checkbox" value="<%=row++%>" /></td>

<TD> <div align="center"><%= resultset.getString(1) %></div></td> <TD> <div align="center"><%= resultset.getString(2) %></div></TD>

</TR>

<% } %>

When retrieving values, use

String rows[] = request.getParameterValues("ck1");

and iterate over the array to find out which rows were selected

Hope that helps

benubacha at 2007-7-10 14:19:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Another approach would be instead of putting in a row, put the id of the record you are currently on. Then you get a String[] of selected ids. Very useful when you want to select a bunch of stuff to delete.
evnafetsa at 2007-7-10 14:19:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Hey Thank you both of you. Will try this.
csp_javaa at 2007-7-10 14:19:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...