• Post Reply Bookmark Topic Watch Topic
  • New Topic

About EL and Integer

 
Tang Yue
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%request.setAttribute("Two","2");
Integer One = new Integer(1);%>
${One + 1}
${Two}
${Two + 1}

Why the correct answer is 1 2 3 ?
In ${One + 1}, how is the "One" processed?
I think the EL should do auto-unboxing, so the answer should be 2 2 3, but it's wrong.

Or, does EL has access to the object ONE , declared in a scriplet, at all?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does EL has access to the object ONE , declared in a scriplet, at all?

No, EL cannot access scriptlets variables, so One is not visible. EL will convert both One and 1 into a BigInteger. If you check EL's conversion rules, you'll see that for a Number, null or "" becomes 0. So One becomes a BigInteger whose value is 0. ${0 + 1} -> 1.
 
It runs on an internal combustion engine. This ad does not:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!