Search code examples
jspforeachjstllinkedhashmap

How to Loop the List of LinkedHashMap and get Key and Values in JSTL


My java class is returning the values like List>>. In JSTL, How do I print the LinkedHashMap Key and List .

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

</c:forEach>

Solution

  • 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>