java - JSTL <c :forEach> not supports List<Integer>?

标签 java jsp jstl

                            ${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); 

我已经被这个问题困扰了一段时间了,谁能帮我解决这个问题吗?谢谢。

最佳答案

刚刚在我的应用程序中检查了它,因此将其作为答案:尝试从 items="${test}" 中删除空格。否则,您将执行与此 java 表达式 ""+ testList 等效的内容。显然,结果不是一个列表。

${sharedType} 的“[1”“2”“3”迭代 3 次
很可能只有一次迭代,您将看到 test.toString() 调用的结果。

关于java - JSTL <c :forEach> not supports List<Integer>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4597073/

相关文章:

java - 如何在 JSP 中显示动态生成的 svg 图像(使用 Spring MVC)?

java - 如何在jsp中访问struts2属性值?

jsp - Sublime Text : any good package for JSP development (jSTL & tag lib)?

java - 在单个应用程序中配置同一个 jar 的两个版本

java - 在 OAuth 2.0 安全 Web 应用程序上使用 JMeter 脚本进行性能测试

javadoc @global 或 @memberAttribute

java - 为什么JSP中EST到PDT的转换错误?

java - 我应该使用哪种 jSTL?

javascript - 在JSP中设置变量并在jquery中使用它

java - 防止忘记在 Spring 中配置事务