0

I tried to run EL function on Tomcat v7 server but it failed.

JSP:

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

Error:

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

So I tried the following code

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

or

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

Error:

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

How can I solve this problem?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
senam
  • 3
  • 1
  • 4

1 Answers1

0

As far as I have understood the problem.You have defined the method as static So calling it With class name is perfectly fine just one thing you missed is you should use scriplet there.

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

To be able to use the EL you must define the instance in one of the scope like Session, Request or Page then only you can use it.

Note:- you should also define the instance incidentTpEtt before calling the str_hl method.

Shirishkumar Bari
  • 2,692
  • 1
  • 28
  • 36
  • I changing code -> ${QStr.str_hl( incidentTpEtt.rceptCtts)} – senam Apr 28 '16 at 07:22
  • Why negative vote ? Are you expecting full solution just by looking at few lines of code ??? I have given him an example that with these lines he can't use `EL` but he should use `scriplet`. – Shirishkumar Bari Apr 28 '16 at 09:12