JSP error: [method] must be used with a prefix when a default namespace is not specified

So, in a JSP I needed to compare two strings so I tried something like this:?

<c:if test="${strVal.equalsIgnoreCase(otherVal)}">
  ...
</c:if>

This of course was followed by the following error:

JSP error: equalsIgnoreCase must be used with a prefix when a default namespace is not specified

Silly me… you can’t do that in a JSP like that. But you can use the function (fn) expression language tag library with some common function implementations. So, the above becomes this:

<%@ taglib uri="https://java.sun.com/jsp/jstl/functions" prefix="fn">
  ...
<c:if test="${fn:containsIgnoreCase(strVal, otherVal)}">
  ...
</c:if>

Related Posts

Leave a Reply