• 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
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

String Operators in EL

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

EL code
-----------------------------------
${"a"+2}
OUTPUT = 3
-----------------------------------

Normal Scripting
----------------------------------
<%
out.println("1"+2);
%>

OUTPUT :- 12
----------------------------------

Can someone tell me why there is difference in output?... isn't it should be same
[ June 04, 2007: Message edited by: deepak adlakha ]
 
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

${"a"+2}
OUTPUT = 3


Really ? Did you mean ${"1"+2} ?
EL treats arithmetic operations as "arithmetic", not string concatenation. The rule is then different from Java.
With an addition, the container tries to convert both arguments into numbers, and sums them up.
 
deepak adlakha
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yup i meant ${"1"+2} only.

Thanks for explaination. But why it treats different as compare to java ?
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Thread hijack removed]
[ June 04, 2007: Message edited by: Bear Bibeault ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic