java - jsp中用foreach显示列表中的列表

标签 java jsp jstl

是否可以在jsp中使用foreach在列表中显示列表的元素?

List<List<String>> elements;

我在想这样的事情:

<c:forEach var="charge" items="${customerOfferForm.offersWithCharges.get(0)}">

最佳答案

您的语法将在 EL 2.2 中工作(从 Servlet 3.0 容器开始可用,例如 Tomcat 7、Glassfish 3 等),但在旧版本中不起作用。然后您可以使用大括号符号 []通过索引获取所需的列表项。

<c:forEach items="${customerOfferForm.offersWithCharges[0]}" var="charge">
    ...
</c:forEach>

如果需要,您可以使用嵌套 <c:forEach>显示所有项目。

<c:forEach items="${customerOfferForm.offersWithCharges}" var="offerWithCharges">
    <c:forEach items="${offerWithCharges}" var="charge">
        ...
    </c:forEach>
</c:forEach>

另请参阅:

关于java - jsp中用foreach显示列表中的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8895630/

相关文章:

java - 如何检查路径是否存在于java中?

java - 如何从 JSP/Java 中的 double 中获取整数和小数部分?

java - 从网络浏览器录制视频

java - 使用 jsp 检索函数返回的 java 输出

java - 绝对uri : http://java. sun.com/jsp/jSTL/core无法解析

java - 使用 foreach 小时值在 JSTL 中打印

java - 为 SendGrid 创建 JUnit 测试

java - 如何在将 "anonymous"JTextField 添加到组件时禁用它?

java - SOAP 故障 : Failed to assert identity with UsernameToken

jsp - 使用 JSTL/fmt 在 EL 中格式化 GregorianCalendar