JSP CheckBox Example

By: Dorris Emailed: 1607 times Printed: 2080 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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>

JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Dorris
sum of all digits in a given number using Shell Script
sh -x and sh -v in Linux
case..esac..in Linux Shell Script
while loop in Linux Shell Script
Nested for loop in Linux Shell Script
for loop in Linux Shell Script
Multilevel if-then-else in Linux Shell Script
Nested if-else-fi in Linux Shell Script
if...else...fi in Linux Shell Script
test command or [ expr ] in Linux Shell Script
if condition in Linux Shell Script
Download Linux. Which linux and where?
Formula in Hibernate
Primary keys assigned by triggers in Hibernate
Assigned identifiers in Hibernate

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
What are the different scopes in JSP?
Sending Email using JSP
JSP CheckBox Example
JSP Example to connect to MS SQL database and retrieve records
JSP Alert Example
Comparison operators in JSP
JSP Program for display Date
Arithmetic Evaluation Using the Expression Language in JSP
The page Directive in JSP
WebClient: Talking to Web Servers Interactively
Using a DataSource from WebLogic in a JSP
The taglib, tag, include, attribute and the variable Directive in JSP
The Request Object in JSP
Embedding java codes in jsp sciptlets
Sessions in JSP
Most Emailed Articles (in JSP)
Embedding java codes in jsp sciptlets
Packaging Servlets
The Advantages of JSP
Sessions in JSP
What are the different scopes in JSP?
A JSP page that gets properties from a bean
The Advantages of Servlets Over “Traditional” CGI
Retrieving a Portion of a String
Server-side plug-Ins
The taglib, tag, include, attribute and the variable Directive in JSP
Document Object
Web Security Issues
Enable/Disable Scripting Elements in JSP
Scriptlets and Expressions in JSP
The Response Object in JSP