This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "EL" Watch "EL" New topic
Author

EL

sangeeta kapoor
Ranch Hand

Joined: Jun 15, 2004
Posts: 70
There is a person bean with name property. So in my JSP to get the name using EL

${requestScope.person["name"]}

How can I get the same result without using the dot operator and only using the [] operator.

I am doing something like this but this doesn't work
${requestScope[person["name"]]}
Durgaprasad Guduguntla
Ranch Hand

Joined: Oct 20, 2003
Posts: 99
Well, this is a tricky and good question.

requestScope - a java.util.Map that maps request-scoped attribute names to their values.

If you want to use [] operator on the requestScope Map, the value evaluated for the expression used within the [] should be available as "key" for any object stored in the request scope. For example, look at the following JSP:



The output is:

Here person["name"] is evaluated to "Sangeetha" which in turn is the key for object "list" stored in the requestScope Map.

Thanks,

Durga


Thanks,<br />Durgaprasad<br />SCJP1.4, SCWCD1.4, SCBCD1.3,<br />SCEA
P. Dunn
Ranch Hand

Joined: Feb 22, 2005
Posts: 34
I am doing something like this but this doesn't work
${requestScope[person["name"]]}
To put it another way, evaluates to a Person object, not the string "person." The object must be turned into a map key for requestScope. The object is not evaluating to the string you expect.
[ February 23, 2005: Message edited by: P. Dunn ]

P.Dunn<br />SCJP, SCJD, SCEA & SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL
 
Similar Threads
HFSJ page 380
EL Expressions
Bean property
EL expression..[ ] operator
EL expressions . vs [ ]