I am new to JSTL, trying out some examples on EL.
Have set an ArrayList to request/session in
Servlet.
Am trying to iterate the List in
JSP using c:forEach.
Have used:
JSTL1.1, JSP2.0, Servlets2.4, Tomcat5.x
Servlet:
req.setAttribute("testattribute", userList);
sessionObj.setAttribute("userlist", userList);
//userList is the ArrayList
JSP:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
${userlist}
<br />
${testattribute}
<br/>
<c:forEach var="product"
items="$(testattribute}">
<tr><td>${product}</td></tr>
</c:forEach>
</body>
</html>
Output:
[admin, superuser, user, enduser]
[admin, superuser, user, enduser]
$(testattribute}
Its not looping with the request attribute value.
Can you let me know, whats wrong in the above code?