Home > DeveloperSection > Forums > identifying which check boxes are selected using JAVA ( jsp)
Felix Pickles
Felix Pickles

Total Post:24

Posted on    December-07-2015 3:12 AM

 Java Java  Jsp 

 1 Reply(s)
 470  View(s)
Rate this:
I am building  a servlet that displays a simple form with checkboxes , when the user selects the number of checkboxes he wants and clicks on a "confirm" the POST request in my servlet checks for which boxes have been checked and queries the database based .

I am unsure on how to do this in Java as the user may select either 1 or more checkboxes . if somebody could explain this with a small example this would be great.

I am very new to programming and would provide a code snippet if I knew how to do it .

Mayank Tripathi
Mayank Tripathi

Total Post:397

Posted on    December-07-2015 3:22 AM

This is actually the HTML form behavior question. When you check a few checkboxes with one "name" attribute and different "value" attributes and press submit button, your browser will send request to the server with checked checkbox values. So you can get value names from this url parameters.

For example:

<form name="input" action="html_form_action.asp" method="get">
<input type="checkbox" name="vehicle" value="Bike">I have a bike<br>
<input type="checkbox" name="vehicle" value="Car">I have a car 
<input type="submit" value="Submit">
If you check both of checkboxes your server will receive this parameters like so:

After that you can get values like this:

String checkboxValues = request.getParameter("vehicle");
checkboxValues gets all values separated by comma.

Modified On Dec-07-2015 03:23:08 AM

Don't want to miss updates? Please click the below button!

Follow MindStick