在JSP中使用EL时出错:"当未指定默认命名空间时,函数contains必须与前缀一起使用"

ASU*_*SUR 4 jsp jstl el

在我的jsp页面中,我指定:

<c:choose>
line 1: <c:when test="${com.community_classification_id.contains('1')}">
            <input type="checkbox" id="by_invitation1"   name="invitaion" value="1" checked="true">By Invitation<span style="padding-left:28px"></span>
        </c:when>
        <c:otherwise>
            <input type="checkbox" id="by_invitation1"   name="invitaion" value="1">By Invitation<span style="padding-left:28px"></span>
        </c:otherwise>
</c:choose>
Run Code Online (Sandbox Code Playgroud)

但@line没有.1它给我500错误

The function contains must be used with a prefix when a default namespace is not specified
Run Code Online (Sandbox Code Playgroud)

我无法理解它.怎么了?

jel*_*ies 6

看看这个:JSTL fn:contains()函数

用于在另一个内部找到一个String(我想这是你想要实现的)

在你的代码中:

<c:choose>
    <c:when test="${fn:contains(com.community_classification_id, '1')}">
        <input type="checkbox" id="by_invitation1" name="invitaion" value="1" checked="true">By Invitation<span style="padding-left:28px"></span>
    </c:when>
    <c:otherwise>
        <input type="checkbox" id="by_invitation1" name="invitaion" value="1">By Invitation<span style="padding-left:28px"></span>
    </c:otherwise>
</c:choose>
Run Code Online (Sandbox Code Playgroud)

不要忘记在您的JSP中包含taglib以使用它:

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
Run Code Online (Sandbox Code Playgroud)