当未指定默认名称空间时,必须与前缀一起使用

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

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

JSP:

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

错误:

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

所以我尝试了下面的代码

<%@ 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)}">

错误:

The function str_hl cannot be located with the specified prefix

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();
}

我该如何解决这个问题?

据我所知,problem.You 已将方法定义为静态的,因此使用 class 名称调用它非常好,您错过的一件事是您应该 use scriplet .

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

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

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