Robert Martin wrote:
> I am working on a servlet that generates an HTML table where each table row
> contains information about a row in the database along with a checkbox. The
> user selects the checkboxes next to the rows he is interested in performing
> additional processing on and then presses the submit button. This posts the
> information to the next servlet, which presents additional screens. I want
> to send several columns of data for each selected row, but the checkbox POST
> only allows for <name>=<value>. What is the best way to pass multiple
> pieces of information between servlets in this manner? Should I make the
> value a delimited string and have the next servlet tokenize it? Or is it
> better to send one column of data and then have the next servlet re-query
> the database for the other columns? Other better methods? Tnx.
>
> Robert S. Martin
> Software Engineer
> First Quadrant, L.P.
>
You can send multiple values for the same field name. For each row, create a
checkbox like this:
<td>
<input name="checked" type="checkbox" value="xxxxx">
</td>
where "xxxxx" is some unique identifier (such as the primary key) for the
current row. When this form is submitted, the "checked" parameter might have
multiple values, which you can retrieve and process like this:
String keys[] = request.getParameterValue();
if (keys == null)
keys = new String[0]; // No row was selected
for (int i = 0; i < keys.length; i++) {
String key = keys[i];
... do something with this selected row ...
}
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html