• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

EL doubt

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was refering this nice link : old one

I was cross-checking ansers except below all ansers are right and understood and checked

I have below JSP :

<%@ page isErrorPage="true" isELIgnored="false" %>
<html>
<body>

<% java.util.Map map = new java.util.HashMap();
request.setAttribute("map", map);
map.put("a", "b");
map.put ("b", "c");
map.put("c", "d"); %>
${map.c} --- d
${map[c]} -- nothing will print as there is no c attribute
${map["c"]} --- d
${map[map.b]} ---d


${map.map.b} --- nothing printing for this as there is no key "map" in map "map"

${map.map(map.b)} --- error in this case , Please suggest why?? , It could have reacted same as just above one to this EL which i have quoted




</body>
</html>

Please guide me , this EL is too much confusing
 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Vishal Chugh:

${map.map(map.b)} --- error in this case , Please suggest why??



You can use either dot(.) or [] with EL. Not "()"
 
Vishal Chugh
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh yes , Thank you very much

I wonder, how i cant see ()
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am wondering on the fact that in the example given , 1st the request attrbute is been set ,then we are putting the values. So how can the request attribute contain Map with values instead of an empty Map.

Or am i wrong ?

Thanks,
Chithra Salam.A
SCJP 5
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Friend , You are still setting the values to the reference to the Map Object which is in the request Object as attribute.So since you are having the reference to that map ,You can set it from anywhere.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

As we know that EL is about using attributes and implicit objects.
It has, no access to local variables , so before I use any local variable with EL
I have to make the local variable a attribute in any scope. Then only the EL will identify it

in your case "map" is a local variable so to work with EL , it should be made as attribute in any scope
thats the reason they have put it under request scope

I hope this should help you
 
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic