Reading Multiple Checkbox Values in JSP

In this tutorial you will learn how to get multiple checkbox values in JSP.Using checkbox user can select more than one options in a form. We need to use html tag <input type="checkbox"> to create the checkboxes in JSP.

Project Description :

In this example in index.jsp page, checkbox with various options and a submit button is created .In result.jsp page we are getting the selected value using the c:forEach tag.


Directory Structure of Project :

jstl forEach

In this tutorial you will learn how to get multiple checkbox values in JSP.Using checkbox user can select more than one options in a form. We need to use html tag <input type="checkbox"> to create the checkboxes in JSP.

Project Description :

In this example in index.jsp page, checkbox with various options and a submit button is created .In result.jsp page we are getting the selected value using the c:forEach tag.


Directory Structure of Project :

jstl forEach


index.jsp

<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<html>
<head>
<title>JSTL forEach Example</title>
</head>
<body>
	<h1>JSTL forEach Example</h1>
	<form action="result.jsp" method="post">
		<table>
			<tr>
				<td colspan="2"><h3>Please Enter Your Details</h3></td>
			</tr>
			<tr>
				<td>Country:</td>
				<td><select name="country">
						<option>India</option>
						<option>USA</option>
						<option>China</option>
				</select></td>
			</tr>
			<tr>
				<td valign="top">Language</td>
				<td><input type="checkbox" name="language" value="English">English</input><br />
					<input type="checkbox" name="language" value="Hindi">Hindi</input><br />
					<input type="checkbox" name="language" value="Mandarine">Mandarine</input><br />
				</td>

			</tr>

			<tr>
				<td colspan="2">
					<center>
						<input type="submit" value="Send" />
					</center>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>

result.jsp

<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>

<html>
<head>
<title>JSTL forEach Example</title>
</head>
<body>
	<h1>JSTL forEach Example</h1>

	<b>Your Country Selected :-</b>
	<c:out value="${param.country}" />

	<br />
	<b>Your Language Preference is :-</b>

	<c:forEach var="value" items="${paramValues.language}">
		<c:out value="${value}" />
	</c:forEach>
	<br />


	<small><a href="index.jsp">Back to Home</a></small>
</body>
</html>

Output in Browser :

jstl forEach


jstl forEach


Download Example(Developed in Eclipse)





comments powered by Disqus