【问题标题】:must be used with a prefix when a default namespace is not specified [duplicate]当未指定默认命名空间时,必须与前缀一起使用 [重复]
【发布时间】:2016-08-22 18:59:53
【问题描述】:

我尝试在 Tomcat v7 服务器上运行 EL 功能,但失败了。

JSP:

<input type="hidden" name="" id="Rcept_<%=i%>" value="${QStr.str_hl( incidentTpEtt.rceptCtts)}">

错误:

未指定默认命名空间时,函数str2html必须使用前缀

所以我尝试了以下代码

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 
<input type="hidden" name="" id="Rcept_<%=i%>" value="${fn:str_hl(QStr, incidentTpEtt.rceptCtts)}">

或

<input type="hidden" name="" id="Rcept_<%=i%>" value="${fn:QStr(str_hl, incidentTpEtt.rceptCtts)}">

错误:

找不到指定前缀的函数str_hl

QStr:

public static String str_hl(String as_str) {
    char[] l_str = null;                                                    
    int li_len = 0;                                                          
    StringBuffer l_return = new StringBuffer();                               

    if(as_str == null)                                                       
        return null;

    l_str = as_str.trim().toCharArray();
    li_len = l_str.length;

    for(int i=0 ; i<li_len ; i++) {
        if     (l_str[i] == '&')  l_return.append("&amp;");
        else if(l_str[i] == '<')  l_return.append("&lt;");
        else if(l_str[i] == '>')  l_return.append("&gt;");
        else if(l_str[i] == '"')  l_return.append("&quot;");
        else if(l_str[i] == '\'') l_return.append("&#39;");
        else l_return.append(l_str[i]);
    }
    return l_return.toString();
}

我该如何解决这个问题?

【问题讨论】:

    标签: function jsp el


    【解决方案1】:

    据我了解问题。您已将该方法定义为静态因此使用类名调用它非常好,您错过的一件事是您应该在那里use scriplet。

    &lt;input type="hidden" name="" id="Rcept_&lt;%=i%&gt;" value='&lt;%=QStr.str_hl( incidentTpEtt.rceptCtts)%&gt;'&gt;

    为了能够使用 EL,您必须在 Session、Request 或 Page 等范围之一中定义实例,然后只有您可以使用它。

    注意:- 您还应该在调用 str_hl 方法之前定义实例 incidentTpEtt。

    【讨论】:

    • 我更改代码 -> ${QStr.str_hl(incidentTpEtt.rceptCtts)}
    • 为什么要投反对票?您是否期望通过查看几行代码来获得完整的解决方案???我给了他一个例子,在这些行中他不能使用EL,但他应该使用scriplet。
    猜你喜欢
    • 2013-09-28
    • 2012-10-31
    • 1970-01-01
    • 2012-10-12
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    相关资源
    最近更新 更多