• 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 Qz

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

What will happen when you attempt to compile and run the following JSP page contents?

<%
request.setAttribute("Two","2");
Integer One = new Integer(1);
%>

${One + 1}
${Two}
${Two + 1}

The answer is: 123
I can't understand it. Can anybody figure it out? Thanks alot.
 
Ranch Hand
Posts: 246
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please refer page 399 of HFSF(Head First Servlets & JSP), 2nd Edition.

Thanks & regards,

Naveen Katoch
 
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

I can't understand it.


What exactly don't you understand ? 1 ? 2 ? 3 ?
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by liqiang yang:
Hi all,

What will happen when you attempt to compile and run the following JSP page contents?

<%
request.setAttribute("Two","2");
Integer One = new Integer(1);
%>

${One + 1}
${Two}
${Two + 1}

The answer is: 123
I can't understand it. Can anybody figure it out? Thanks alot.



$(One + 1) : evalauates to 0 + 1 = 1 ( Attribute with name "One" could not be found in any of the scope, so EL consider it as 0 in arithmetic operation) (considered as false in logical operation)

${Two) : it is simpe. attribute names "Two" is found in scope and its value is 2.

${Two + 1} : Simple.Value of attribute "Two" (2) + 1 = 3

so it prints: 123 (There are no line breaks)

Regards

Prem Kashyap
[ May 14, 2008: Message edited by: Prem Kashyap ]
 
Ranch Hand
Posts: 598
3
jQuery Google App Engine Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by liqiang yang:

<%
request.setAttribute("Two","2");
Integer One = new Integer(1);
%>

${One + 1}
${Two}
${Two + 1}

The answer is: 123
I can't understand it. Can anybody figure it out? Thanks alot.



Well,
1)One is evaluated to null so null + 1 is 1 (I am not sure ,sorry)
2)Two is String and evaluated to primitive (if you put "rft" instead of
"2" you will get big fat exception)
3)Two("2") is evaluated to 2 and 2+1 = 3

As to 'One',I am not sure so other ranchers will take care of it

best regards,
omi
[ May 14, 2008: Message edited by: omi sharma ]
 
Prem Kashyap
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I said in my previou post, null is evaluated as 0 in arithmetic operation (+,- etc) and evaluated as false in logical operation(&&,|| etc)). (For relational operation, like <, >, >= etc , i am not sure if it evaluated to 0 or false. my guess it evaluated to false. Just write a small program and find out.

Regards
Prem Kashyap
 
liqiang yang
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks ranchers!!!

I make sense and feel better now.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic