Here is the simple way to pass the check box value from a .jsp page to a Java controller.
Step 1: Model Class - Initialize the checkbox variable in the model class.
Step 2: JSP page - Take a checkbox item and provide the name attribute as declare a variable in a Model class. Like - checkBoxItem
Here have a c:if, which checking the value of checkBoxItem is Y or not with the page loading. If the value is Y then it makes the check box a checked.
Code -
<input type="checkbox" name="checkBoxItem" value="Y" <c:if test="${model.checkBoxItem=='Y'}">checked="checked"</c:if> />
Step 3: Controller Class - Now we can get the value using @ModelAttribute
Finally Output :
0 Comments