无法在 JSTL 循环中获取 Map<Integer, String> 值

Unable to get Map<Integer, String> values in JSTL Loop

我正在尝试在 JSP 页面中呈现的 Servlet 中设置地图值,如下所述:

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>

问题是我没有从这个循环中获取 Map<> 值,我可以使用 System.out 在 Servlet 中看到值,但我认为 '${item.id}' 值没有正确传递,这这就是 Map 没有返回任何值的原因。

有人可以在这里指导我吗?如果需要更多解释或说明,请告诉我。

谢谢!

尝试使用这个:-

<c:forEach var="item" items="${itemList}">
   <c:set var="id" value="${item.id}"/>
   <h4><c:out value="${anotherItemMap[id]}"/></h4>
</c:forEach>