首页 > 解决方案 > 如何在 JSTL 中循环 LinkedHashMap 列表并获取键和值

问题描述

我的 java 类返回 List>>之类的值。在 JSTL 中,如何打印 LinkedHashMap Key 和 List 。

<c:forEach var="row" items="${myList.data}"> // Main List
    <DIV>
       <span option="1">${row.key}</span> // Getting empty key
    </DIV>

</c:forEach>

标签: jspforeachjstllinkedhashmap

解决方案


what is .data if it is list ? I think .data will not come.Your loop should be like this

<c:forEach items="${myList}" var="map"> 
<c:forEach var="entry" items="${map}">
<tr><td><c:out value="${entry.key}"/></td> <td><c:out value="${entry.value}"/> </td></tr>
</c:forEach>
</c:forEach>

推荐阅读