i’m trying to pass a List<String[]> object to my jsp page and handle it with jstl.
my servlet:
request.setAttribute("rows", entries);
request.getRequestDispatcher("/pages/result.jsp").forward(request, response);
page:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
${rows}
<c:forEach items="${rows}" var="row">
<tr>
<c:forEach items="${row}" var="field">
<td>${field}</td>
</c:forEach>
</tr>
</c:forEach>
the params are not recognized – meaning they are printed as ${rows} and ${field}
the funny thing is that when i do the same using this way (which i understand is bad practice):
<%
List<String[]> entries = (List<String[]>) request.getAttribute("rows");
for...
%>
what am i missing?
So, EL expressions are not evaluated? That can happen when there’s a version incompatibility between the JSTL version used, the servletcontainer version used and the webapp’s
web.xmlversion.First you need to figure which Servlet API version is max supported by the target servletcontainer. Then you can determine which JSTL version you actually need and which version the
web.xmlshould be declared to.Imagine that you’re using Tomcat 7, which is a Servlet 3.0 compatible container, then you should be using at least JSTL 1.2 and the
web.xmlshould be declared conform Servlet 3.0. Or if you’re using Tomcat 6, which is a Servlet 2.5 compatible container, then you should be using at least JSTL 1.1 and theweb.xmlshould be declared conform Servlet 2.5.A more rare cause, but not uncommon among beginners, is that webapp’s
/WEB-INF/libis incorrectly been cluttered with servletcontainer-specific JAR files such asel-api.jarand so on, which would only conflict the EL installation provided by the target servletcontainer itself.See also: