将c:forEach变量传递给一个jsp:include [英] Passing c:forEach variable to a jsp:include

查看:391
本文介绍了将c:forEach变量传递给一个jsp:include的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



示例:
$



 < c:forEach items =$ {cart.entries}var =entry> 
< jsp:include page =helper.jsp>< / jsp:include>
< / c:forEach>

里面的helper.jsp我想能够引用变量'entry'。它不断出现空。我想也许有可能有一种方法来增加范围到forEach变量像正常的设置变量一样。



有什么想法?

解决方案

 < c:forEach items =$ {cart.entries}var = 条目 > 
< c:set var =entryFCvalue =$ {entry}scope =request>< / c:set>
< jsp:include page =helper.jsp>< / jsp:include>
< / c:forEach>

然后我引用了我的include中的entryFC。不是非常优雅的,但它的工作,所以我想不适应去与它。


I am trying to access some JSTL variables that were set on a JSTL for-loop in an include.

Example:

<c:forEach items="${cart.entries}" var="entry">
 <jsp:include page="helper.jsp"></jsp:include>
</c:forEach>

Inside helper.jsp I want to be able to reference the variable 'entry'. It keeps coming up as 'empty'. I thought maybe there might be a way to add scope to the forEach Variable like you can with normal set variables.

Any ideas?

解决方案

ANSWER: I ended up just having to do this to get it to work.

<c:forEach items="${cart.entries}" var="entry">
<c:set var="entryFC" value="${entry}" scope="request"></c:set>
 <jsp:include page="helper.jsp"></jsp:include>
</c:forEach>

Then i referenced the entryFC in my include. Not very elegant at all but its working so i guess ill go with it.

这篇关于将c:forEach变量传递给一个jsp:include的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆