I am trying to get the Map values set up in a Servlet rendered in a JSP page as explained below:
Servlet Code
Map<Integer, String> anotherItemMap = new HashMap<>();
for (Item item : itemList) {
anotherItemMap.put(item.getId(), "someValue");
}
request.setAttribute("itemList", itemList);
request.setAttribute("anotherItemMap", anotherItemMap);
request.getRequestDispatcher(forwardToAddress).forward(request, response);
JSP Code
<c:forEach var="item" items="${itemList}">
<h4><c:out value="${anotherItemMap['${item.id}']}" /></h4>
</c:forEach>
Problem is I am not getting the Map<> Values from this loop, I can see the values in Servlet with System.out
but I think the '${item.id}'
value is not getting passed properly and this is why Map is not returning any value.
Could anyone please please guide me here? Let me know if any more explanation or clarification needed.
Thanks!