Accessing Request/session attributes using JSTL

1 1 1 1 1 1 1 1 1 1 Rating 2.50 (1 Vote)
JSTL and EL together provide an easy way to access session, request and application scope varibles. EL provides implicit variables like sessionScope, requestScope, applicationScope and many more which are actually Map type. They can be navigated easily by using dot operator to access any attributes added to it.
Below JSP code provides a simple way of accessing and displaying the values.
Note that we have added the scriplet in the page, just to show that we are adding value in session and request variables. Scriplets should be avoided when JSTL and EL are used.
<%@ taglib uri="" prefix="c" %>
<%//Scriplets are not to be used
request.setAttribute("param1", "Hello JSTL World!");
session.setAttribute("userName", "Generic User");


Hello <c:out value="${sessionScope.userName}"/>,</p>
Welcome to <c:out value="${requestScope.param1}"/>,</p>
It provides a output as below:
Hello Generic User,
Welcome to Hello JSTL World!,

Joomla SEO by MijoSEF