• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL doubt

 
Vishal Chugh
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
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • 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 ()
 
Chithra Salam
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
 
Baddy Davay
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.
 
Salim Khatib
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic