0

I've an HashMap like this one {1={descrizione=prova2, post_file=2.PNG., postID=2, userID=37}, 2={descrizione=prova2, post_file=2.PNG., postID=2, userID=37}}, and I pass it from the servlet (where it's generated) to a JSP page. In this page I'd like only to get the descrizione, post_file and userID attributes.

I've tried many things, first of all I did a nested for loop that printed everything

<c:forEach var="entry" items="${post}">
    <c:forEach var = "risultati" items = "${entry}">
        <div id = "post">
            <div>${risultati.value}</div>
        </div>
    </c:forEach>    
    <br>
</c:forEach>

This worked, then I tried to do

<div>${risultati["postID"}</div> or <div>${risultati.postID}</div> but I got errors (javax.el.PropertyNotFoundException: Property [values] not found on type [java.util.HashMap$Node]) or nothing happened.

I have tried to search a lot but I have not found anything, could please anyone help me out with this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

2 Answers2

0

I've found this solution and it works, i don't know if it's the best one

<c:forEach var="entry" items="${post}">
    <div id = "post">
        <div>${post[entry.key]['postID']}</div>
    </div>
</c:forEach>
0

When iterating a HashMap, each var is a Map.Entry. To access the inner map, you have to use entry.value.

<c:forEach var="entry" items="#{post}">
    <div id = "post">
        <div>${entry.value['postID']}</div>
    </div>
</c:forEach> 
areus
  • 2,880
  • 2
  • 7
  • 17