I need to do for each loop and include loops content to other jsp page. Now 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>
The include directive is used to include the contents of any resource it may be jsp file, html file or text file. The include directive includes the original content of the included resource at page translation time (the jsp page is translated only once so it will be better to include static resource).
JSTL foreach tag allows you to iterate or loop Array List, HashSet or any other collection without using Java code. After the introduction of JSTL and expression language(EL) it is possible to write dynamic JSP code without using scriptlet which clutters jsp pages.
Full Stack Java developer - Java + JSP + Restful WS + Spring The <c:forEach> tag is a commonly used tag because it iterates over a collection of objects. The <c:forTokens> tag is used to break a string into tokens and iterate through each of the tokens.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With