Access Servlet Session Attribute Using JSTL


In Java this piece of code, request.getSession().getAttribute(“my_var”) can be accessed using JSTL with the sessionScope keyword. To access my_var, call sessionScope.myvar.

Remember to use sessionScope because if your Java code looks like this: request.getAttribute(“my_var”) will not work. See sample JSTL code below.

1
<c:out value="${sessionScope.my_var}"/>

Found this post useful? Buy me a cup of coffee or subscribe to my RSS feeds and Google Friend Connect

Remove Session Attribute In JSTL


Removing session attributes using Java code goes like this

1
request.getSession().removeAttribute("my_var");

To do the same thing in JSTL, do this

1
<c:remove var="my_var" scope="session"/>

Found this post useful? Buy me a cup of coffee or subscribe to my RSS feeds and Google Friend Connect

Related Posts with Thumbnails