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 tag of Core JSTL tags

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="http://java.sun.com/jsp/jstl/core" %>

show.jsp

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<c:if test="${pageContext.request.method=='POST'}">
<c:choose>
<c:when test="${param.add!=null}">
<c:if test="${list!=null}">
<c:set var="list" value="${list}," scope="session" />
</c:if>
<c:set var="list" value="${list}${param.item}"
scope="session" />
</c:when>
<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:if>
<c:set var="list2" value="${list2}${item}" />
</c:if>
</c:forEach>
<c:set var="list" value="${list2}" scope="session" />
<c:remove var="list2" />
</c:when>
</c:choose>
</c:if>
<html>
<head>
<title>Updatable Collections</title>
</head>
<body>
<table border="0">
<form method="post">
<tr bgcolor="blue">
<td colspan="2">
<font color="white">Add and remove application</font>
</td>
</tr>
<tr>
<td valign="top">
<select NAME="choice" SIZE="5">
<c:forEach var="item" items="${list}">
<option>
<c:out value="${item}" />
</option>
</c:forEach>
</select>
</td>
<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" />
</td>
</tr>
</form>
</table>
</body>
</html>

submit.html

<html>
    <head>
        <title>Page Data Example</title>
    </head>    
    <body bgcolor="#585858">
        <table bgcolor="#D8D8D8">
            <form method="POST" action="show.jsp">
                <tr>
                    <td width="33%">
                        <b>First Name</b>
                    </td>                    
                    <td width="73%">
                        <input type="text" name="first" size="40" />
                    </td>
                </tr>               
                <tr>
                    <td width="33%">
                        <b>Last Name</b>
                    </td>
<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