Reading Session Attributes Using JSTL

Reading Session Attributes Using JSTL explains about how to access JSTL's session scoped attributes such as variables inside a JSP page

session is an implicit object available in JSP, so it is very easy to access the session scoped varaibles inside JSP page

You can access the session scoped varaibles in following different ways

<c:out value='${sessionScope["variableName"]}'/>
<c:out value='${sessionScope.variableName}'/>

you can see the below complete example demonstrating how to access session scoped attributes in JSTL EL expression

Required Libraries

You need to download

  1. Tomcat 9
  2. JSTL 1.2

Following jar must be in classpath

  1. jstl-1.2.jar

Reading Session Attributes Using JSTL

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="java.util.ArrayList"%>
<%
	ArrayList<String> numList = new ArrayList<String>();
	numList.add("one");
	numList.add("two");
	numList.add("three");
	session.setAttribute("numList", numList);
%>
<html>
<body>
	// access the session scoped varaibles inside JSP page in two different ways
	<c:out value='${sessionScope["numList"]}' /><br/>
	<c:out value='${sessionScope.numList}'/>
</body>
</html>

Output
[one, two, three]
[one, two, three]

 











Your email address will not be published. Required fields are marked *