在jsp中使用foreach显示列表中的列表 [英] Display a list in a list with a foreach in jsp

查看:133
本文介绍了在jsp中使用foreach显示列表中的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to display the elements of a list in a list with a foreach in a jsp?

List<List<String>> elements;

我想的是:

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


推荐答案

您的语法适用于EL 2.2(可用)从Servlet 3.0容器,如Tomcat 7,Glassfish 3等),但不是旧版本。然后,您可以使用括号符号 [] 按索引获取所需的列表项。

Your syntax will work in EL 2.2 (which is available since Servlet 3.0 containers such as Tomcat 7, Glassfish 3, etc), but not in older versions. You can then use the brace notation [] to get the desired list item by index.

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

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

You can if necessary use a nested <c:forEach> to display all items.

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



参见:




  • 我们的EL维基页面

  • See also:

    • Our EL wiki page
    • 这篇关于在jsp中使用foreach显示列表中的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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