JSP CheckBox Example
By: Dorris Printer Friendly Format
JSP CheckBox is used to create a CheckBox in JSP. The JSP Page allows the user to select more than one option from multiple checkbox and also print the user-defined message that specifies the 'languages' option chosen by the user on submitting the button.
This Tutorial illustrates an elaborate example of 'JSP CheckBox'. To understand and grasp the example we create a CheckBox.jsp page that includes the html tag<input type="checkbox"> to create the checkboxes. The HTML page allows the user to select multiple languages using checkboxes. After submitting the button, the action is performed which displays the selected languages. The method request.getParameter Values("id") is used to return the value of selected checkbox. The for loop is used to execute the code repeatedly till the length of variable i is less than equal to selected position of checkbox. Finally the out.println is used to print the selected checkbox in the browser.
jspCheckBox.jsp
<html>
<h2>Select Languages:</h2>
<form ACTION="jspCheckBox.jsp">
<input type="checkbox" name="id"
value="Java"> Java<BR>
<input type="checkbox" name="id"
value=".NET"> .NET<BR>
<input type="checkbox" name="id" value="PHP">
PHP<BR>
<input type="checkbox" name="id"
value="C/C++"> C/C++<BR>
<input type="checkbox" name="id"
value="PERL"> PERL <BR>
<input type="submit" value="Submit">
</form>
<%
String select[] = request.getParameterValues("id");
if (select != null && select.length != 0) {
out.println("You have selected: ");
for (int i = 0; i < select.length; i++) {
out.println(select[i]);
}
}
%>
</html>
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Subscribe to Tutorials
Related Tutorials
Archived Comments
1. Great job, its really helpful
View Tutorial By: Viveka at 2016-01-25 01:44:48
2. nqwzvzCep
View Tutorial By: nhnejnCep at 2017-08-29 01:50:03
3. nqnqotCep
View Tutorial By: naapqqCep at 2017-09-06 01:20:53
4. nmcqcoCep
View Tutorial By: nokwzwCep at 2017-09-16 09:38:44