Categories
Java

JSP/Servlets and Form Checkboxes

This one caught me off-guard.

Suppose you have a form with multiple checkboxes that share the same name. You check off some boxes and submit the form.

In ColdFusion, checkbox values submitted from a form are presented to you inside a variable that contains a comma-delimited list of the checked values.

Java does not play the same way.

In Java, what you get is an array of Strings that is returned when you as the request object for the parameter of the name the checkboxes share. You then need to iterate through the array to get all the values and do whatever you wish with them.

What surprised me is that there is really no mention of this behavior in any of the books I checked or around the web. Well, it is noted now.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

 

Share