Home Jsp Simple-jsp-example JSTL: Removing Session Attribute
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JSTL: Removing Session Attribute

Advertisement
In this example we are going to remove the session attribute which we have set in the session. For this we are going to use the core action library, so we need to use the jstl core library provided by the Sun MicroSystems in our example.

JSTL: Removing Session Attribute

        

In this example we are going to remove the session attribute which we have set in the session. For this we are going to use the core action library, so we need to use the jstl core library provided by the Sun MicroSystems in our example. 

Use the <c:set> core action to set the variable. The variable will get stored in the attribute var and its value will be specified in the attribute value and its scope will be set in the attribute scope. We are going to delete the scoped varible in the next jsp page so we have given a link to it.  In this page firstly we are going to retrieve the value of the scoped variable by using the implicit object sessionScope. At last we will remove the session scoped variable by using the <c:remove> tag.  Later if we want to see the scoped variable then it will show no scoped variable. 

The code of the program is given below:

 

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
        <c:set var="setVariable" value="roseindia.net" scope="session" />
        <html>
  <head>
    <title>Set a scoped attribute</title>
  </head>
  <body>
    The value which has to be removed will get removed
    by this page  <br><a href="JSTLRemovingSessionAttribute.jsp"> <b>Click</b> </a>Here to go to next page.
  </body>
        </html>

 

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
        <html>
  <head>
    <title>Removing a scoped attribute</title>
  </head>
  <body>
    In this page we are removing the session-scoped attribute <br><b> <c:out value="${sessionScope.setVariable}" /> </b><br>
    <c:remove var="setVariable" scope="session" />
    The value is now "<c:out value="${sessionScope.setVariable}" />"
  </body>
        </html>

The output of the program is given below:

Download this example.

        

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: March 12, 2008

Related Tutorials

Ask Questions?    Discuss: JSTL: Removing Session Attribute  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com