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.
<% 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 ]
SCJP, OCA 9i application developer, SCWCD 5.
When I was in hell someone told me to get heaven you need to do Java.
Prem Kashyap
Ranch Hand
Joined: Oct 10, 2006
Posts: 52
posted
0
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
Joined: Jan 20, 2008
Posts: 92
posted
0
Thanks ranchers!!!
I make sense and feel better now.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.