shyamli
shyamli

Reputation: 49

get key and value from hashmap in jsp

I have a hashmap as HashMap<String, Object>
How can I get key and some Bean variable from the object value in the JSP form?

HashMap<String, Object> labelList = populateFieldLabels(users);
model.addAttribute("labelList", labelList);

I have already tried this:

<c:out value="${labelList.key}"></c:out>

Upvotes: 0

Views: 2827

Answers (2)

Jekin Kalariya
Jekin Kalariya

Reputation: 3507

You can iterate maps like this

<c:forEach items="${labelList}" var="label">
    <c:out value="${label.key}"></c:out>
</c:forEach>

Upvotes: 2

Prasad Kharkar
Prasad Kharkar

Reputation: 13556

If you need to iterate through map,

<c:forEach items="${labelList}" var="item">
    <c:out value="${item.key}"></c:out>
</c:forEach>

Upvotes: 1

Related Questions