2016-04-28 76 views
0

我試圖在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(); 
} 

我怎樣才能解決這個問題?

回答

0

就我所瞭解的問題而言。你已經將靜態方法定義爲靜態所以用類名稱來調用它是完全正確的,只是你錯過了一件事情,那就是你應該在那裏使用use scriplet

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

爲了能夠使用EL您必須如會話範圍的一個定義實例,請求或頁面那麼只有你可以使用它。

注意: - 在調用str_hl方法之前,您還應該定義實例incidentTpEtt

+0

我改變代碼 」 值= '<%= QStr.str_hl(incidentTpEtt.rceptCtts)%>'> - > $ {QSTR .str_hl(incidentTpEtt.rceptCtts)} – senam

+0

爲什麼反對投票?你是否期待完全的解決方案,只需看幾行代碼?我給了他一個例子,他用這些方法不能使用'EL',但他應該使用'scriplet'。 –

相關問題