Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in EL

 
Shobhana Sundar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I've this following code

<%
java.util.Map map = new java.util.HashMap();
request.setAttribute("map",map);
map.put("a","b");
map.put("b","c");
map.put("c","d");

%>

Now i want to know which EL will print the value "d".

A. ${map.c}
B. ${map[c]}
C. ${map["c"]}
D. ${map.map.b}
E. ${map[map.b]}

My choice was A,C,D. But it turns out that the answer is A,C,E.

If B is wrong then E evalueates to ${map[c]} right? So E should also be wrong? How come D is wrong?

Someone please explain.

Regards
Shobhana
 
P Chittaranjan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answere shold be A, C and E.

When we say ${map} , it means request.getAttribute("map").
So ${map} will give the HashMap Object( here map) added to request.
for
A.${map.c}--> same as map.get("c")-->will give "d"
B.${map[c}}--> is same as map.get(99)--> int value of c.
C.${map["c"]}--> same as map.get("c")--> will give "d".
D.${map.map.b}-->same as map.get("map").get("b")-->so no key is there with name "map" in the map.
E.${map[map.b]}--> same as map.get(map.get("b"))-->here the internal map.get("b") will give "c". So output will be "d".

Very nice question.

Thanks
Chittaranjan
 
Shobhana Sundar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chittaranjan,

Thnaks for the reply. I'm clear now. Actually for D i was evealuating the . operator from right to left and wondering why the result was not matching.

Regards
Shobhana
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic