jsptomcatjstl

Misbehaving JSTL forEach


Problem definition: JSTL tags work in my JSP with the exception of forEach. Behavior is that it ignores request objects. It works for objects created on the page, but for objects coming in from request it fails. My ignorant view is that it appears to not be detecting the request object. I can save you a lot of questions by confirming that a scriplet and some Java code confirms that the ArrayList arrives to the JSP, and I have even processed it item for item and proven that the list was in fine shape. Rest assured, the list DOES make it to the JSP and I am currently relying on scriplet to make the app work.

That being said, here is my (questionable?) configuration:

  1. Tomcat 10.1.25

  2. WEB-INF/lib/jakarta.servlet.jsp.jstl-3.0.1.jar, jakarta.servlet.jsp.jstl-api-3.0.0.jar

  3. In JSP header: <%@taglib prefix="c" uri="jakarta.tags.core"%>

  4. The offending forEach loop:

     <c:forEach items="${prodList}" var="prods">
       <c:out value="Inside forEach ..."/>
       <c:out value="${prods.prodID}"/>
       <c:out value="${prods.prodName}"/>
    </c:forEach>
    
  5. Servlet: request.setAttribute("prods", prodList);

  6. Project Deployment Assembly: /src/main/webapp = /

  7. Project buildpath has the two JSTL jars

  8. Strangely, when I type <c:forEach to create the tag it immediately barfs and says there is a problem with, and I quote, "org.apache.taglibs.standard.tei.ForEachTEI, which is a class that I have doubts about. It is a member of the aforementioned jakarta.servlet.jsp.jstl-api-3.0.0.jar (org/apache/taglibs/standard/tei/ForEachTEI.class). But whence the jakarta namespace? Why apache?

This stuff makes me want to tear the rest of my hair out.

Bottom line is that scriptlet works and the tag does not. The tag appears to simply ignore any request objects. Yes, other tags work. It's about forEach.


Solution

  • I feel like an idiot but I had REVERSED the items and var! There was nothing wrong with the JSTL libs, just my brain was wired wrong when staring at the problem of the items being EMPTY. Null items object means nothing happens, as if the forEach is braindead. It wasn't. It was doing what I asked it to do!