Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read data from HashMap using JSTL tag in JSP without using for each or for loop

Tags:

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?

like image 290
Ankur Mukherjee Avatar asked Mar 22 '11 17:03

Ankur Mukherjee


People also ask

How to iterate list of HashMap in JSP using JSTL?

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.

Is for loop used in JSTL?

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.

How do I iterate in JSTL?

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.


1 Answers

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).

like image 139
BalusC Avatar answered Nov 11 '22 13:11

BalusC