Open the HTML page that contains your checkbox markup.
Position your mouse cursor at the line directly after the closing form tag – “” – that encloses the checkbox.
Type the JSP script identifier – “<%” – used to signify the beginning of the JSP script. Type it at the start of the next line of the file.
Type, starting at the next line in the file, code that will store the value of the checkbox in a string variable named “checkboxvalue.” Use the “request.getParameterValues” command. Specify the argument of the getParameterValue method to be the value of the “name” assigned in the “ " statement in your HTML checkbox markup.
String checkboxvalue = request.getParameterValues(“firstCheckBox”); if (checkboxvalue.length > 0) { out.println(“The Check Box Value of the First Checkbox is “); out.println(checkboxvalue); }
In this code, the value in the HTML checkbox markup tag with the name “firstCheckBox” is stored in a string variable named “checkboxvalue” The if then statement checks if the number of characters in “checkboxvalue” is greater than 0, to check if a value was assigned in the checkbox HTML markup.
For this example, the JSP checkbox was specified with the HTML markup code:
Charge Your Visa
In this statement a checkbox component is assigned a variable name of “firstCheckBox” that has the value (text string) “Visa Card.” stored in it.
Type, starting at the next line of the file, the JSP script identifier used to signify the end of a JSP script – “%>” – to close the code.
Save the HTML file and upload the saved version to your website. Navigate to the page and select the checkbox on the page, then click the “Submit” button. The message “The Checkbox Value of the First Checkbox is: Visa Card” will be displayed on the line.
Writer Bio