Passing parameters to another JSP file using <jsp:include> tag
80,037
Solution 1
<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}"/>
Solution 2
An alternative would be using setAttribute()
and getAttribute()
Solution 3
Another alternative is using JSTL tag c:set and request scope.
<c:set var="instance" value="${your.value}" scope="request"/>
<jsp:include page="instance.jsp"/>
Solution 4
The solution that work for me is the following
<c:set var="instance" value="${semaforoData}" scope="request"/>
<jsp:include page="semaforo.jsp"/>
in the jsp file, the code is:
<c:forEach var='itemSemaforo' items='${semaforoData}' varStatus='loopSemaforo'>
Print data
</c:forEach>
Author by
SIGSTP
Updated on May 20, 2021Comments
-
SIGSTP almost 3 years
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 variableinstanceVar
. I want to do it using JSTL. Is there any way to do this? -
Gangnus over 6 yearsAnd how can I access the param.myVar in the java code in the included jsp, please?
-
Alex over 6 yearsThe question was about JSTL. And it is better not to mix java code with JSTL.
-
Roshana Pitigala about 6 years@SpringLearner
setAttribute()
ofHttpSession
orHttpServletRequest
? -
Francisco M over 4 yearsIt worked*. but in my case, I wasn't allowed to pass a list. The jsp complier raise an error saying which the params has to be static (value="some static value"). Is not to downvote it but it didn't solved my problem.
-
Francisco M over 4 yearsWorked for me and give me the chance to pass any kind of dynamic objects. It don't pass really the parameters, but, create a variable in the page/backing class which can be used in the included jsp.