【问题标题】:How can I get the value of element which inside of an Arralyst in my JSP with JSTL tag?如何使用 JSTL 标记获取我的 JSP 中 Arraylist 内部的元素的值?
【发布时间】:2013-11-18 00:03:35
【问题描述】:

我想获取 ArrayList 中每个元素的值,这些元素已作为 request.setAttribute 传递给 JSP。

当我编写下一个代码时,我可以获得 ArraList 中每个元素的值:

  <table border="1">
  <c:forEach var="item"  items="${ListCompanies}">
  <td><b><c:out value="${item.string2}"/></b></td>
  <td><b><c:out value="${item.string3}"/></b></td>
  </c:forEach>
  </table>

但是,我不知道如何在没有 foreach 操作的情况下直接获取值

类似的东西:

<c:out value="${ListCompanies.string2}"/>

谁能告诉我如何管理 c:out 以从元素中获取价值?

【问题讨论】:

  • 试试${ListCompanies.get(i).string2} 其中i 代表你要显示的项目的索引
  • 非常感谢它有效,你有任何链接,我可以找到更多关于它的文档。
  • 这是在 Java 中访问 List 中元素的方式。

标签: java jsp jstl


【解决方案1】:

类似

<c:out value="${ListCompanies[0].string2}" />

<c:out value="${ListCompanies[1].string3}" />

【讨论】:

    猜你喜欢
    • 2012-12-30
    • 1970-01-01
    • 2012-05-20
    • 1970-01-01
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    • 2018-12-23
    • 1970-01-01
    相关资源
    最近更新 更多