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?
You can use JSTL <c:forEach> tag to iterate over arrays, collections and maps. In case of arrays and collections, every iteration the var will give you just the currently iterated item right away. In case of maps, every iteration the var will give you a Map.
The <c:for each > is an iteration tag used for repeating the nested body content for fixed number of times or over the collection. These tag used as a good alternative for embedding a Java while, do-while, or for loop via a scriptlet.
JSTL - Core <c:forEach>, <c:forTokens> Tag The <c:forEach> tag is a commonly used tag because it iterates over a collection of objects. The <c:forTokens> tag is used to break a string into tokens and iterate through each of the tokens.
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)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With