Home Jsp Learn about JSP CheckBox
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Learn about JSP CheckBox

Advertisement
The tutorial highlights that what is JSP CheckBox and how it is used during various steps and it also suggests you in getting the multiple checkbox values in JSP.

Learn JSP CheckBox

The tutorial highlight the features by whihc you will be able to know what is JSP checkbox and also how it works in creating a checkbox in JSP. Further, you can know in details about the multiple chechbox values in JSP by the tutorial. The JSP Page allows the user to select more than one option from multiple checkbox and also print the userdefined message that specify the languages option chosen by the user on submitting the button.

Understand with Example

An example will be helpful in demonstrating the facts as from 'JSP CheckBox'. To understand and grasp the example we create a CheckBox.jsp that include the html tag <input type="checkbox"> to create the checkboxes. At this point, one thing appear here which shows the HTML page allows the user to select multiple languages using checkbox. After submitting the button, the action is performed which display the selected languages. If you submit the matter without checking alert box will display a message like please select your favorite.

The important features about the fact it that methodrequest.getParameter Values ("id") is used to return the value of selected checkbox. It is noted that the for loop is used to execute the code repeatedly till the length of variable i is less than equal to select position of checkbox. Thus the out.print ln is used to print the selected checkbox in the browser.

Here is the code of 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>

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 9, 2013

Related Tutorials

Ask Questions?    Discuss: Learn about JSP CheckBox  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com