The behavior == does not change, but the behavior of {expr} ...
About versions:
In the backward compatibility section of the JSP specification,
If the version specification is less than 2.1, then the syntax {expr} is simply treated as a string literal.
So, until EL 2.0 everything will be considered as a string literal and compared to .equals , since == will be converted to equals internally ( Link here ), but in 2.1. It will not be converted to a string and will throw an exception saying javax.el.ELException: Cannot convert No of type class java.lang.String to class java.lang.Long
About Comparison:
In the JSP specification JSP.2.3.5.7 version EL 2.1, the following is indicated ...
If A is null or B is null, return false for == or eq, true for! = Or ne
If A or B is Byte, Short, Character, Integer or Long, and B in Long, use the operator
therefore in the first case
${1 =="" } // ans is false as second one is null as per 1st rule.
and in the second case
${1 =="4" } // ans is false as both are different after coercing to Long as per 2nd rule.
Both will be forced to long in the case of internal type conversion.
But not in the third case, ${1 =="Yes" } , where the second line cannot be converted (forced) to Long and java.el.ELException will be passed with the message "It is not possible to convert the class No of type java.lang.String to class java.lang.Long ".
Not a bug
source share