Get value of HashMap by specific key in EL without iterating over it
Asked Answered
S

1

24

I want to read data from a HashMap using EL in a JSP page, but without the use of JSTL <c:forEach> or a for loop. How can I do this?

Shanty answered 22/3, 2011 at 17:23 Comment(0)
C
63

Just use the map key as if it were a bean property:

${map.key}

This does under the covers the same as map.get("key").


Or via the brace notation if the key contains dots:

${map['key.with.dots']}

This does under the covers the same as map.get("key.with.dots").


Or if the key is another variable:

${map[dynamicKey]}

This does under the covers the same as map.get(dynamicKey).

Crosshatch answered 22/3, 2011 at 17:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.