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.

JSTL: Removing Session Attribute

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.