Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

doubt in EL

 
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
 
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
 
It means our mission is in jeapordy! Quick, read this tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic