Capture list of checked rows from JSP

In JSP page I need to show records with the checkbox. The user ticks the one or more records that need to be 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.

Let me assume that u have 3 fields as one record...and you are displaying each records with one checkbox.These records are shown using Jsp.While displaying every record , hope you will be using one "for loop" and adding the checkbox at the right end or left end of the row.Each record would have one primary key value ..say for example..employee number or something..so you can have the primary key value of each record as the check box values(ex:emp no) and checkbox name as some useful text.

so , while displaying 10 records, you will have 10 checkboxes which has 10 unique values...right?..now..u r ticking some check boxes...and submitting this form to a servlet...you can get the ticked check box values at the servlet using getParameterValues()..This function will return an array of all the unique values of checkboxes...right?...then u can execute the delete query in a "for loop" ,using these unique values in where condition to delete the records from the table..

Hope , you could have understood the flow .

Josephine Anthony

Greenhorn

Posts: 3

posted 13 years ago

Hi Rajaguru,

Thank you for your timely help. I understood the flow and I am implementing as per your flow.

May be in future, I use struts. Will the same flow applicable or do I need to extract the checked rows in different way?

Thank you again Jo

Originally posted by Rajaguru Ramalingam: Hi Josephine,

Let me assume that u have 3 fields as one record...and you are displaying each records with one checkbox.These records are shown using Jsp.While displaying every record , hope you will be using one "for loop" and adding the checkbox at the right end or left end of the row.Each record would have one primary key value ..say for example..employee number or something..so you can have the primary key value of each record as the check box values(ex:emp no) and checkbox name as some useful text.

so , while displaying 10 records, you will have 10 checkboxes which has 10 unique values...right?..now..u r ticking some check boxes...and submitting this form to a servlet...you can get the ticked check box values at the servlet using getParameterValues()..This function will return an array of all the unique values of checkboxes...right?...then u can execute the delete query in a "for loop" ,using these unique values in where condition to delete the records from the table..