• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

EL doubt

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


a It will print 1 because the statement is valid.
b It will print 2 because the statement is valid.
c It will throw an exception because a is undefined.
d It will throw an exception because the expression’s syntax is invalid.

and the ans is a..

can smbody help me in this..
also if i replace a by "a" it will give give ERROR..
 
Greenhorn
Posts: 8
IntelliJ IDE Netbeans IDE Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EL treats undefined variables as null or zero. So "5 + 3 + a" evaluates to "5 + 3 + 0". This is > 0 so 1 is printed.

Regards
Herman
 
narendra bhattacharya
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Herman Pomstra wrote:EL treats undefined variables as null or zero. So "5 + 3 + a" evaluates to "5 + 3 + 0". This is > 0 so 1 is printed.

Regards
Herman



Thanks Herman
 
Creator of Enthuware JWS+ V6
Posts: 3409
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

also if i replace a by "a" it will give give ERROR..



That is correct, "a" is a String that does not represent a number and cannot be translated into a number like for instance "15".
${"Not a Number" + 3} will evaluate in a javax.servlet.jsp.el.ELException

If you use:
${(5 + 3 + a > 0) ? 1 : 2}
the EL-parser will try to find an attribute in one of the 4 scopes named 'a' and if it is not found it will be treated as an 0 or null like Herman is saying (@ Herman congratulations on your result!)

Have a look at some EL examples in my notes (ScwcdLinks)

Regards,
Frits

 
This guy is skipping without a rope. At least, that's what this tiny ad said:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic