Reading Request Attributes Using JSTL

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

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

You can access the request scoped varaibles in following different ways

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

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

Required Libraries

You need to download

  1. Tomcat 7
  2. JSTL 1.2

Following jar must be in classpath

  1. jstl-1.2.jar

Reading Request 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");
	request.setAttribute("numList", numList);
%>
<html>
<body>
	<c:out value='${requestScope["numList"]}' /><br/>
	<c:out value='${requestScope.numList}'/>
</body>
</html>
Output
[one, two, three]
[one, two, three]

 






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