How can I use the equals() method in a JSP?
Question
In my JSP I need to test two objects using the equals()
method. Is there a way to do this using EL, JSTL, or another tag library? I am not allowed to use scriptlets due to team rules.
I tried to use the JSTL <c:if>
tag, but it only seems to use the ==
operator.
Solution
The JSP Expression Language operator ==
(or its alias, eq
) performs comparison with the equals
method, although some coercions are performed if one of the objects is a special type (BigDecimal, BigInteger, Double, Float, Long, Integer, Short, Byte, Character, Boolean, or String). You shouldn't need a tag for this, just ${a == b}
. If that doesn't fit in your context, could you please post more information?
OTHER TIPS
The J2EE 1.4 guide has an example of just that. You'll have to setup your once function lib, but it doesn't look hard.