【问题标题】:Error using EL in JSP: "The function contains must be used with a prefix when a default namespace is not specified"在 JSP 中使用 EL 时出错:“未指定默认命名空间时,函数包含必须与前缀一起使用”
【发布时间】:2012-07-30 06:49:40
【问题描述】:

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

我无法理解。怎么了?

【问题讨论】:

    标签: jsp jstl el


    【解决方案1】:

    看看这个:JSTL fn:contains() function

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

    在您的代码中:

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

    【讨论】:

    • 我不明白...我的回答对您有所帮助,但您接受了另一个?这是一个错误? XD
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2012-10-31
      • 1970-01-01
      • 2016-08-22
      • 2013-09-28
      • 2012-10-12
      • 2012-01-10
      • 2015-05-15
      • 1970-01-01
      • 2011-02-01
      相关资源
      最近更新 更多