Home Jstl Example of Variable Support Tags of JSTL Core Tag Library



Example of Variable Support Tags of JSTL Core Tag Library
Posted on: August 1, 2008 at 12:00 AM
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

Related Tags for Example of Variable Support Tags of JSTL Core Tag Library:
javacweblibraryidestlfunctionapplicationfuniotagssedjstlpagevicoretaguriapplicationsthisidfunctionalappsimplejsforieexampleunctopagesstandardexameilitdeslibliuseimmaninrarlibrariesstamcajndaesfuncagehowproppcatxaxampseeatanyishallmplfunctionalityandarsimvassrirdthavstatiaphatlibrariemanyicaicapleplprndono


More Tutorials from this section

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
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.