Behavior of ==
is not changed but behavior of {expr}
is changed...
About versions :
In backward compatibility section of JSP Specification,
If the version specified is less than 2.1, then the {expr} syntax is
simply processed as a String literal.
So, till EL 2.0 all will be treated as a string literal and compared with .equals
as ==
will be converted to equals
internally (Reference here), but in 2.1 It will not be converted to string and will throw exception saying that javax.el.ELException: Cannot convert No of type class java.lang.String to class java.lang.Long
About Comparision :
In JSP specification JSP.2.3.5.7 of EL version 2.1, following is specified...
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 coerce both A
and B to Long, apply operator
so, In first case,
${1 =="" } // ans is false as second one is null as per 1st rule.
and In second case,
${1 =="4" } // ans is false as both are different after coercing to Long as per 2nd rule.
Both will be coerced to long in above case with internal type conversion.
But not in the third case,
${1 =="Yes" }
where second one is string can not be converted (coerced) to Long and java.el.ELException
will be thrown with message "Cannot convert No of type class java.lang.String to class java.lang.Long".