Tech-Freaks.in

Technically Driven To Perfection!

  • Increase font size
  • Default font size
  • Decrease font size
Home Rapid Code Accessing Request/session attributes using JSTL

Accessing Request/session attributes using JSTL

E-mail Print
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="http://java.sun.com/jstl/core" 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!,

(0 Votes)

Add your comment

Your name:
Subject:
Comment: