Passing parameters to another JSP file using

2019-01-10 21:54发布

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?

标签: jsp include jstl
4条回答
smile是对你的礼貌
2楼-- · 2019-01-10 22:39
<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}"/>
查看更多
戒情不戒烟
3楼-- · 2019-01-10 22:42

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>
查看更多
干净又极端
4楼-- · 2019-01-10 22:44

An alternative would be using setAttribute() and getAttribute()

查看更多
Explosion°爆炸
5楼-- · 2019-01-10 22:53

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"/>
查看更多
登录 后发表回答