jspforeachjstlscopejspinclude

Passing c:forEach variable to a jsp:include


I am trying to access some JSTL variables that were set on a JSTL for-loop in an include.

Example:

<c:forEach items="${cart.entries}" var="entry">
 <jsp:include page="helper.jsp"></jsp:include>
</c:forEach>

Inside helper.jsp I want to be able to reference the variable 'entry'. It keeps coming up as 'empty'. I thought maybe there might be a way to add scope to the forEach Variable like you can with normal set variables.

Any ideas?


Solution

  • ANSWER: I ended up just having to do this to get it to work.

    <c:forEach items="${cart.entries}" var="entry">
    <c:set var="entryFC" value="${entry}" scope="request"></c:set>
     <jsp:include page="helper.jsp"></jsp:include>
    </c:forEach>
    

    Then i referenced the entryFC in my include. Not very elegant at all but its working so i guess ill go with it.