Hi All,
In JSP page I need to show records with the checkbox. The user ticks one or more records that need to delete and clicks the submit button as one action. At the server side, the servlet should extract all the ticked rows and perform delete task. This exercise is to avoid multiple delete action by the User. Now my question is how to store the checked rows in the page and send to server to process. Any help on this is appreciated.
Thanks in advance
Jo
-
Submit action with a list of checkbox from JSP (3 messages)
- Posted by: Josephine Anthony
- Posted on: June 10 2004 00:41 EDT
Threaded Messages (3)
- Submit action with a list of checkbox from JSP by Paul Strack on June 10 2004 11:21 EDT
- Submit action with a list of checkbox from JSP by Josephine Anthony on June 10 2004 20:23 EDT
- Submit action with a list of checkbox from JSP by Paul Strack on June 11 2004 11:02 EDT
- Submit action with a list of checkbox from JSP by Josephine Anthony on June 10 2004 20:23 EDT
-
Submit action with a list of checkbox from JSP[ Go to top ]
- Posted by: Paul Strack
- Posted on: June 10 2004 11:21 EDT
- in response to Josephine Anthony
Give every checkbox the same name, but different values:
<input type="checkbox" name="selection" value="1">
<input type="checkbox" name="selection" value="2">
<input type="checkbox" name="selection" value="3">
In the servlet/JSP, use request.getParameterValues() with the checkbox name. You will get an array of strings containing the values of the selected checkboxes.
String[] selections = request.getParameterValues("selection");
// If the user checked boxes one and three, this array will be {"1", "3"}
If you make the checkbox values the primary key for each record, the delete operations should be easy. -
Submit action with a list of checkbox from JSP[ Go to top ]
- Posted by: Josephine Anthony
- Posted on: June 10 2004 20:23 EDT
- in response to Paul Strack
Thank you Paul Strack,
I am implementing as per your example. How about if I use struts form?
Regards
Jo -
Submit action with a list of checkbox from JSP[ Go to top ]
- Posted by: Paul Strack
- Posted on: June 11 2004 11:02 EDT
- in response to Josephine Anthony
My Struts is kind of rusty. A quick survey of the Struts website indicates that the multibox tag may do what you want.
However, I have found that with these kinds of controls, it is easier to generate your UI elements "manually" rather than using framework control (which rarely handle this kind of complex UI element just the way you need it to).