开发者

fetching values from map in jstl

I have the following code on my jsp page:

<c:out value="${items}"开发者_如何学Python /><br />

<c:forEach items="${items}" var="item">
     1. <c:out value="${item.key}" /><br />
     2. <c:out value="${item.key eq 70}" /><br />
     3. <c:out value="${items[70]}" /><br />
     4. <c:out value="${items[item.key]}" /><br />
</c:forEach>

And it produces the following output

{70=true}
1. 70
2. true
3.
4. true 

And I just can't figure out why 3. is empty. Any ideas?

The map is of type Map<Integer, Boolean>


Basically autoboxing puts an Integer object into the Map.

map.put(new Integer(0), "myValue")

EL evaluates 0 as a Long and thus goes looking for a Long as the key in the map. i.e. it evaluates:

map.get(new Long(0))

As a Long is never equal to an Integer object, it does not find the entry in the map. That's it in a nutshell.

Refer forum http://forums.sun.com/thread.jspa?messageID=9702932#9702932

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜