4

在我的 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>

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

The function contains must be used with a prefix when a default namespace is not specified

我无法理解。怎么了?

4

2 回答 2

6

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

用于在另一个字符串中找到一个字符串(我想这是你想要实现的)

在您的代码中:

<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>

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

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
于 2012-07-30T07:24:40.373 回答
1

您可以在 EL 中使用您的静态方法(我假设com.community_classification_id.contains是),但首先您必须定义自定义 EL 函数。

检查这个答案这个答案,它显示了如何在 JSP 中创建和使用 EL 函数。然后只需记住导入您的 taglib 并使用带有前缀的静态方法,如这些答案中所示。

于 2012-07-30T07:21:19.807 回答