JSTL不支持List?
${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}
<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>
The integer list is 1,2,3.
On my page, it show [1,2,3] for ${test}, and "[1" "2" "3" for ${sharedType} in 3 iterations. Looks like JSTL think it is a String separated by comma rather than a list.
The code to generate the list in java is:
List<Integer> test= new ArrayList<Integer>();
test.add(1);
test.add(2);
test.add(3);
I have been struggling with this for a while, can anyone help me with this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚在我的应用程序中检查了它,因此将其作为答案:尝试从
items=" ${test}"
中删除空格。否则,您将执行与此 java 表达式" " + testList
等效的内容。显然,结果不是一个列表。3 次迭代中 ${sharedType} 的“[1”“2”“3”
很可能只有一次迭代,并且您看到的是
test.toString()
调用的结果。Just checked it in my app and so put it as an answer: try removing space from
items=" ${test}"
. Otherwise, you're executing equivalent of this java expression" " + testList
. Obviously, the result is not a list.and "[1" "2" "3" for ${sharedType} in 3 iterations
Most likely there was only one iteration and you're seeing the result of
test.toString()
call.