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 Question on EL: If it’s NOT a String literal, it’s evaluated 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 "Question on EL: If it’s NOT a String literal, it’s evaluated" Watch "Question on EL: If it’s NOT a String literal, it’s evaluated" New topic
Author

Question on EL: If it’s NOT a String literal, it’s evaluated

Hasnain Javed Khan
Ranch Hand

Joined: Nov 23, 2007
Posts: 73
Hello All.
I have a question that is confusing me regarding EL. The following line is taken from HFSJ 2nd Edition

If there are no quotes inside the brackets, the Container evaluates what’s inside the brackets by searching for an attribute bound under that name, and substitutes the value of the attribute


Here is what I tried in a JSP



No output when using " [] " but got MyName printed when using "." .
Can anyone kindly explain why "name" inside [] cannot be resolved by the container since the attribute "name" is present in session scope ? Am I missing some point/information ?
I'm using tomcat 6.16.

Kind regards.
Hasnain Javed.
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 452



here in the first case that is without quotes, container starts looking for an attribute in all the scopes and gets the value MyName.
hence and there is no any attribute in the sessionScope named MyName hence nothing is printed.

in the second case container looks for the key named "name" in the map of session attributes. it finds one with the value MyName and is printed.

avi sinha


SCJP 5.0 SCWCD 5.0
Hasnain Javed Khan
Ranch Hand

Joined: Nov 23, 2007
Posts: 73
avi sinha wrote:
here in the first case that is without quotes, container starts looking for an attribute in all the scopes and gets the value MyName.
hence and there is no any attribute in the sessionScope named MyName hence nothing is printed.


It was so trivial (Thanks to HFSJ => There are no Dumb Questions). It implies I need to give my brain some rest
Thanks Avi .

Kind Regards.
Hasnain.
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 452

Hasnain Javed Khan wrote:Thanks Avi .
Kind Regards.
Hasnain.


you're welcome

avi sinha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on EL: If it’s NOT a String literal, it’s evaluated
 
Similar Threads
Drag and Drop using jQuery
EL Implicit object paramValues
Web Service doesn't read my parameter
Multiple file output with JDK 6 XSLT implementation
how to copy and modify element's attribute ?