Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSP, JSTL. Problem with variables and methods

Tags:

jsp

jstl

I have some problem with using jstl. I have this:

<jsp:useBean id="view" class="user.View"></jsp:useBean>
<jsp:useBean id="user" class="user.Validation" scope="session"></jsp:useBean>

<c:if test="${user.getValid() == 0}">
<c:out value="${view.printUserData(user)}"></c:out>
</c:if> 

and View class looks:

package user;

import java.lang.StringBuilder;

public class View {
    public String printUserData(Validation val) {
        String name = val.getImie();

        mainText.append(name);

        return mainText.toString();
    }

}

but i have error:

org.apache.jasper.JasperException: /save.jsp(30,0) The function getValid must be used with a prefix when a default namespace is not specifie

How can i fix it?

like image 461
Tomasz Gutkowski Avatar asked Jul 07 '11 09:07

Tomasz Gutkowski


1 Answers

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

This error message is typical when you are not using/running a Servlet 3.0 capable container yet, such as Tomcat 7, Glassfish 3, etc. Invoking arbitrary methods in EL is not supported until Servlet 3.0.

So, if you can't upgrade to Servlet 3.0, then you should specify the property name instead.

<c:if test="${user.valid == 0}">

You would also need to approach ${view.printUserData(user)} differently. I'd use an EL function for this.

<c:out value="${f:printUserData(view, user)}">

with

public static String printUserData(View view, Validation validation) {
    return view.printUserData(validation);
}
like image 181
BalusC Avatar answered Oct 17 '22 11:10

BalusC