Home Jsp Simple-jsp-example Using of [] operator of EL with the Map
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Using of [] operator of EL with the Map

Advertisement
This page discusses - Using of [] operator of EL with the Map

Using [ ] operator of EL with the Map

        

EL expressions are always used within curly braces, and prefixed with a dollar($) sign and $(expression). The first named variable in the expression is either an implicit object or an attribute stored in one of the the four scopes i.e. page, request, session, or application. The [] operator is much more powerful than the dot, because it lets you access Map key or a bean property name as well as the access to arrays and Lists.

Map stores the values in the form of a key- value pair. Map can't have a duplicate keys, and each key is associated with at least one value. In map we can retrieve the value by using ${map["0"]}.

We have made one program on map by using the EL . We are retrieving the values of a map firstly by setting the map attribute and thereafter retrieving the value by using the key associated with the map.

The code of the program is given below:

 

<%@ page import = "java.util.*"%>
<% Map map = new HashMap();
map.put("name", "Tim");
map.put("address", "200,Saint Thomas Loop");
map.put("state", "Virginia, USA");
request.setAttribute("useMap", map);
request.setAttribute("userName","name");
%>
<body>
<center>
<table>
<tr><td><b>The name is :</td></b> <td><b>${useMap[userName]}</tr></td></b><br>
<tr><td><b>The first element in Map is :</td></b> <td><b>${useMap["name"]}</tr></td></b><br>
<tr><td><b>The second element in Map is : </td></b> <td><b>${useMap["address"]}</tr></td></b><br>
<tr><td><b>The third element in Map is : </td></b> <td><b>${useMap["state"]}</tr></td></b><br>
</table>
</center>
</body>

The output of the program is given below:

Download this example.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Ask Questions?    Discuss: Using of [] operator of EL with the Map  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com