Forums Register Login

servlet and checkbox state

+Pie Number of slices to send: Send
suppose there are 5 checkboxes and a submit button which goes in servlet.now how to known which checkboxes are checked and which are not from the servlet
+Pie Number of slices to send: Send
You need to put name and value for each checkbox.
Go through a HTML tutorial real quick.
+Pie Number of slices to send: Send
Only the values from the checkboxes which are checked will be sent to the servlet. Retrieve the values using getParameterValues(String).
For example, given this snippet of HTML
<form>
<input type=checkbox name=Test value=1>One
<input type=checkbox name=Test value=2>Two
<input type=checkbox name=Test value=3>Three
</form>
If the user checked the boxes labelled One and Three, then this code in your servlet
String[] values = req.getParameterValues("Test");
will result in values being a 2 element String array such that one element will be "1" and the other element will be "3".
That feels good. Thanks. Here's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1273 times.
Similar Threads
JSP not able to submit FORM when there are more than 100 Check box
retrieving users' bookmarks
how to get selected check box values in struts?
Updation on checkboxes in JSP
form inputs in servlets
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:32:56.