Share on Google+Share on Google+

Using tag of Core JSTL tags

In this example we have used Core JSTL tag that is used to get values from an array, here paramValues returns an array of String type of request.

Using <c:forEach> tag of Core JSTL tags


In this example we have used Core JSTL tag <c:forEach> that is used to get values from an array, here paramValues returns an array of String type of request.  Tag <c:forEach> is member of Core tag library of JSTL so before using Core JSTL tags we must include following line of code :-

  <%@ taglib prefix="c" uri="" %>


<%@ taglib uri="" prefix="c" %>
<c:if test="${pageContext.request.method=='POST'}">
<c:when test="${param.add!=null}">
<c:if test="${list!=null}">
<c:set var="list" value="${list}," scope="session" />
<c:set var="list" value="${list}${param.item}"
scope="session" />
<c:when test="${param.remove!=null}">
<c:set var="list2" value="" />
<c:forEach var="item" items="${list}">
<c:if test="${item!=param.item}">
<c:if test="${list2!=''}">
<c:set var="list2" value="${list2}," />
<c:set var="list2" value="${list2}${item}" />
<c:set var="list" value="${list2}" scope="session" />
<c:remove var="list2" />
<title>Updatable Collections</title>
<table border="0">
<form method="post">
<tr bgcolor="blue">
<td colspan="2">
<font color="white">Add and remove application</font>
<td valign="top">
<select NAME="choice" SIZE="5">
<c:forEach var="item" items="${list}">
<c:out value="${item}" />
<td valign="top">Enter a item to add or remove.
<br />
<input type="text" name="item" size="20" />
<br />
<input type="submit" name="add" value="Add" />
<input type="submit" name="remove" value="Remove" />


        <title>Page Data Example</title>
    <body bgcolor="#585858">
        <table bgcolor="#D8D8D8">
            <form method="POST" action="show.jsp">
                    <td width="33%">
                        <b>First Name</b>
                    <td width="73%">
                        <input type="text" name="first" size="40" />
                    <td width="33%">
                        <b>Last Name</b>
<td width="73%"> <input type="text" name="last" size="40" /> </td> </tr> <tr> <td width="33%"> <b>Qualification</b> </td> <td width="73%"> <SELECT NAME="gourl"> <OPTION VALUE="">Select.. <OPTION VALUE="mca">MCA <OPTION VALUE="btech">B.Tech <OPTION VALUE="be" >BE </SELECT> </td> </tr> <tr> <td width="33%"> <b>Address</b> </td> <td width="73%"> <TEXTAREA NAME="address" ROWS=3 COLS=30> </TEXTAREA> </td> </tr> <tr> <td width="33%"> <b>City</b> </td> <td width="73%"> <input type="text" name="city" size="20" /> </td> </tr> <tr> <td width="33%"> <b>State</b> </td> <td width="73%"> <input type="text" name="state" size="20" /> </td> </tr> <tr> <td colspan="2"> <input type="submit" value="Submit" name="action"/> <input type="reset" value="Reset" name="action" /> </td> </tr> </form> </table> </body> </html>

Steps to run this example :

1:  Download the zip file of code and unzip this file, you will get a folder named  'submit_form_jstlCore'.
2:  Paste this folder in 'Apache Tomcat 6.0.16-->webapps' or generally in directory 'C:\apache-tomcat-6.0.16\webapps'.
3:  Start tomcat server by click on startup.bat file in 'C:\apache-tomcat-6.0.16\bin'.
4: Open browser and type url 'http://localhost:8080/submit_form_jstlCore/submit.html' or click on this link.

When program will run in browser this will show the following output.....

when user will fill all the fields and click on submit button, next response will be.......

Download Source Code


Posted on: August 7, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

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.

Discuss: Using tag of Core JSTL tags  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image