Home Jstl Example of Variable Support Tags of JSTL Core Tag Library
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Example of Variable Support Tags of JSTL Core Tag Library

Advertisement
JSTL( Java Sever pages Standard Tag Library) provide simple tags of core functionality that are used in many web applications.

Example of Variable Support Tags of JSTL Core Tag Library

     

JSTL( Java Sever pages Standard Tag Library) provide simple tags of core functionality that are used in many web applications. JSTL provides four tag libraries, here in this example we will see how to use core tag library of JSTL. uri for JSTL Core library is......

   http://java.sun.com/jsp/jstl/core

So before use Core JSTL tags we must include following line of code :-

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

JSTL core library provides following two tags for variable support....

1 :-   set :  Tag <c:set > is used to initialize a variable with some given value.
  For Example : <c:set var="name" value="Mahendra" scope="request" />
  Here we are initialize variable 'name' with value 'Mahendra'. We can also define scope of this variable by using attribute scope.

2:-  remove :  Tag <c:remove> is used to remove a scoped variable from a particular scope.
   For Example : <c:remove var="name" scope="request" />

In the example given below defines the use of variable support tags of JSTL Core tag library. We have also used tag <c:out> to show the variable in standard output device.
jstlExample.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"  %>
<html>
  <head>
    <title>Using Choose,Otherwise and When</title>
  </head>
  <body>
  <h2>This is Variable Support tags example of JSTL.</h2>
  <c:set var="fName" value="Mahendra" />
        <c:set var="lName" value="Singh" />
		<h3>Welcome.......
            <c:out value="${fName}" />
            <c:out value="${lName}" />
        </h3>
        <c:remove var="fName" />
     <!--variable fName will not show any 
         value because it has removed. -->
        <c:out value="${fName}" />
		<c:out value="${lName}" />
  </body>
</html>

Steps to run this example : 

1:  Download the zip file of code and unzip this file, you will get a folder named  'var_support_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/var_support_jstlCore/jstlExample.jsp' or click on this link.

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

Download Source Code

Advertisements

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: August 1, 2008

Ask Questions?    Discuss: Example of Variable Support Tags of JSTL Core Tag Library  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Baruch Atta
April 28, 2012
Trying to get it to work

What is the difference between these two statements? <% String ok = "true"; %> <c:set var="ok" value="true" /> What I am trying to do is to use a html form, receive the entries in the form, and use the entered data.
DMCA.com