File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes retriving attributes using EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "retriving attributes using EL" Watch "retriving attributes using EL" New topic

retriving attributes using EL

rajaraman navaneethan
Ranch Hand

Joined: Feb 26, 2005
Posts: 86
dear friends,
please go thru the 2 lines of code and clear my doubt

Somwhere in a servlet i have the following code.........

Using requestDispatcher i forward the control to a JSP where i hav the following code snippet.........

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...
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
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".
Annie McCall

Joined: Apr 17, 2003
Posts: 21
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 ]

Annie McCall<br />SCJP 1.4<br />SCWCD
rajaraman navaneethan
Ranch Hand

Joined: Feb 26, 2005
Posts: 86
hi Sathish BS,Ann McCall
thanx for your i am comfortable with the concept....
I agree. Here's the link:
subject: retriving attributes using EL
It's not a secret anymore!