This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

retriving attributes using EL  RSS feed

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear friends,
please go thru the 2 lines of code and clear my doubt

Somwhere in a servlet i have the following code.........
getServletContext().setAttribute("user","Ram");

Using requestDispatcher i forward the control to a JSP where i hav the following code snippet.........
${applicationScope["user"]}

This code retreives the value Ram correctly,but in HFSJ pg:375,it is given that while retreiving an attribute we should not use " ",while using [] operator.
kindly clarify my doubt...
regards
Raja
 
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raja,
I am afraid to say that you have misunderstood the material. I request you to go through it again. When you say, ${applicationScope["user"]}, the container will look for a key called user in the map "applicationScope". As you would know, applicationScope is a map of the context-scoped attributes. You could also say ${applicationScope.user}.

If you say ${applicationScope[user]}, it would evaluate user - which means it would look for a scoped attribute named user and use the value of that attribute as the key into the map applicationScope.

${applicationScope[user]} ==> ${applicationScope["Ram"]} ===> null,

unless you have an attribute bound under the name "Ram".
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajaraman,

I think it says in HFSJ on page 375 "Without quotes, it will not work". So, you do need quotes. This pertains to Beans and Maps. If it was an ArrayList, you don't need quotes. I think if you read further on page 375, it says you may see something like this:
request.setAttribute("Genre", "Ambient");
Music is ${musicMap[Genre]}.
(This will work since Genre evaluates to a literal value from
request object.)

Hope this helps.
[ August 30, 2005: Message edited by: Ann McCall ]
 
rajaraman navaneethan
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Sathish BS,Ann McCall
thanx for your explanations.now i am comfortable with the concept....
regards,
Raja
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!