Including JSP page inside forEach loop
I need to do for each loop and include loops content to other jsp page. N开发者_开发知识库ow I need to pass looped variable to other JSP page. I have tried following, but it didn't work. When I used attribute in included page, it just returned null value.
<c:forEach var="item" items="${items}" varStatus="loop">
<jsp:include page="/my_jsp_page.jsp" flush="true">
<jsp:param name="item" value="${item}" />
</jsp:include>
</c:forEach>
You can store the "item" into request attribute before call jsp:include
<c:set var="item" scope="request" value="${item}">
then read it from the request scope
This is because jsp:param
sets a request parameter, not a request attribute.
From within your included page, you'll have to refer to item
like this:
${param['item']}
Note that, since we're talking about request parameters here, those parameters will always be strings. If this doesn't do it for you, you should follow @Boris' advice above.
精彩评论