Passing parameters to another JSP file using <jsp:include> tag

SIGSTP picture SIGSTP · Oct 3, 2013 · Viewed 75.2k times · Source

I have a JSP file and in that file I am including another JSP file:

<c:forEach var="instanceVar" items="${instanceList}">
    <c:set var="instance"><jsp:include page="instance.jsp"/></c:set>
    ...
</c:forEach


In the file instance.jsp I want to use a variable instanceVar. I want to do it using JSTL. Is there any way to do this?

Answer

Alex picture Alex · Oct 3, 2013
<c:forEach var="instanceVar" items="${instanceList}">
    <jsp:include page="instance.jsp">
        <jsp:param name="myVar" value="${instanceVar}"/>
    </jsp:include>
</c:forEach>

In the instance.jsp

<c:out value="${param.myVar}"/>