Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
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="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

                         

» View all related tutorials
Related Tags: c xml library file files stl orm ant form io user sed jstl tag parameter transform this js for add

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.