【发布时间】:2011-01-04 18:33:24
【问题描述】:
${test}
<c:forEach items=" ${test}" var="sharedType">
${sharedType}<br/>
<c:if test="${sharedType == 2}" >
<span class="tweet-button"></span>
</c:if>
<c:if test="${sharedType == 1}" >
TEST
<a href="#" class="fbshare-button">Share</a>
</c:if>
</c:forEach>
整数列表是 1,2,3。 在我的页面上,它在 3 次迭代中显示 ${test} 的 [1,2,3] 和 ${sharedType} 的 "[1" "2" "3"。看起来 JSTL 认为它是一个用逗号分隔的字符串,而不是一个列表。 在java中生成列表的代码是:
List<Integer> test= new ArrayList<Integer>();
test.add(1);
test.add(2);
test.add(3);
我已经为此苦苦挣扎了一段时间,有人可以帮我解决这个问题吗?谢谢。
【问题讨论】:
-
尝试删除
" ${test}"中的空间。 -
使用评估 ${} 符号本身的 jstl 版本添加您(如果我没记错的话,它是 jstl-rt),还是 jsp 为您评估它?