By: Dorris in JSP Tutorials on 2010年12月27日 [フレーム]
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>
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in JSP )
Show a calendar for user input in JSP
Encrypting Passwords in Tomcat using Servlets
JSP Tags for SQL to connect to a database
Steps to get a Free SSL certificate for your Tomcat
Uploading a file to a server using JSP
Server Side Programming using JSP
Latest Articles (in JSP)
Show a calendar for user input in JSP
Steps to get a Free SSL certificate for your Tomcat
Encrypting Passwords in Tomcat using Servlets
JSP Tags for SQL to connect to a database
Uploading a file to a server using JSP
Uploading an Image to a Database using JSP
A JSP page that gets properties from a bean
Scriptlets and Expressions in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Show a calendar for user input in JSP
Encrypting Passwords in Tomcat using Servlets
Steps to get a Free SSL certificate for your Tomcat
JSP Tags for SQL to connect to a database
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate