3

As, I think every programming language compares an int and a charon behave of ASCII value of char

I am new to java-Expression-Language. Now here, I have created a .jsp file in NETBEANS 5.5.1

CODE:

   <%=('1' > 2)?"true":"false"%>   //true
    ${('1' > 2)?"true":"false"}    //false

What is difference in these expressions?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Javed Akram
  • 15,024
  • 26
  • 81
  • 118

2 Answers2

7

EL has no notion of char. It's been treated as String. Single or double quotes, it doesn't matter, it's a String.

More detail about EL can be found in EL 2.2 specification.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 1
    As per your deleted comment: The `<% %>` things are JSP *scriptlets*. It's basically "raw" Java code with the same rules as in a normal Java class. That's the difference with EL which has its own rules as you can read in the EL spec. Actually, *scriptlets* should be [avoided](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files) in JSP files. – BalusC Dec 18 '10 at 03:18
  • +1 for giving link to your answer at http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files – Javed Akram Dec 18 '10 at 03:38
4

There is no char literal type in JSP EL. 'a' defines a string containing the single letter a, rather than a java char. The JSP EL evaluator then coerces the two sides to be the same so that they can actually be compared. Numbers have higher precedence than strings, so '1' gets coerced to the integer 1 and then the comparison is done.

Affe
  • 47,174
  • 11
  • 83
  • 83