• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EL ${1} Doubt

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q-2 In servlet I wrote
request.setAttribute("1","one");
and In JSP
${1}

but it's printing 1 as output. Why ?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because EL interprets it as an Integer.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try ${requestScope["1"]}

Head First explains this on page 377.
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Christophe,
Why EL interprets it as an Interger. why not an attribute stored in request scope like it does for others ?

Refer to p-367 and 368...
I am still waiting for the answer
[ March 16, 2008: Message edited by: Sandeep Vaid ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because EL sees 1 as a primitive, not a String.
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Christophe,

in that case does this work {"1"}, hope this is not an integer any more.
clarification please.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In that case does this work {"1"}


Sorry, it won't work either If you want to use a number, you'd have to go through the requestScope map : ${requestScope["1"]}. By the way, it's not a good idea to use primitives as attribute names
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe,
Why EL interprets it as an Interger. why not an attribute stored in request scope like it does for others ?

Refer to p-367 and 368...




Assume musicMap is a map and Genre is an attribtue. Also 1 is an attribute
${musicMap[Genre]} ----- Evaluates To ---> ${musicMap["Ambient"]}
Then

${musicMap[1]} --> If i have set "1" as an attribtue. Why it doesn't gets evalutes to it's value ?

Do you mean it first check inside [] for an integer (or not) then for whether it is an attribute ?

Why it doesn't treat attributes evaluation Genre and 1 alike ?

I know setting 1 as attribute is not a good idea but the exam may test us on this as it's logically correct....
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why it doesn't gets evalutes to it's value ?


Because it's an integer, and EL treats primitives as such. The container sees it as a primitive, not as a named variable. If you really want to use an integer, you'll use the requestScope implicit object. What about arrays ? How the container should treat ${myArray[1]} ?
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this is the case
I think the book should specify it exactly as :

${1} -----> returns 1 (no matter 1 is set as an attribute}
${a} -----> attributes 'a' value
 
reply
    Bookmark Topic Watch Topic
  • New Topic