I’m using the following things for my project:
Spring 3.0.1 + Apache Tiles 2.2.1 + Glassfish 2.1. What I’m trying to do is to call some method in a jsp-page and pass some parameters to it. For example, I have a bean:
@Component
@Scope(value = "singleton")
public class TestBean {
public void test(String param){
System.out.println("param = " + param);
}
}
and I have a jsp-page:
<%@page contentType="text/html; charset=utf-8"%>
${testBean.test("hello")}
This code gives me an exception like:
org.apache.jasper.JasperException: The function test must be used with
a prefix when a default namespace is not specified
If I call some method without passing parameters to it – everything is OK.
I have tried to put jboss-el.jar in my WEB-INF/lib and put required parameters in web.xml (as explained here), but with no effect.
I’m restricted to the set of technologies that I have listed above, so I can’t add anything or, for example, can’t change the version of my app-server.
With all these conditions, is there a solution for my problem?
This indicates that the environment doesn’t support the new EL 2.2 feature of invoking bean methods with arguments. The outdated environment is trying to interpret the expression as an EL function which has the notation
namespace:functionName()(like as JSTL functions). The exception is merely complaining thatnamespace:part cannot be found in order to identify the EL function. But it is wrong, after all.You need to ensure that the following conditions are met in order to be able to invoke bean methods with arguments in EL:
The target container must support EL 2.2. All Servlet 3.0 compatible containers do, as EL 2.2 is part of Java EE 6 which in turn also covers Servlet 3.0. Examples of Servlet 3.0 containers are Tomcat 7.x, Glassfish 3.x and JBoss AS 6.x/7.x.
The
/WEB-INF/web.xmlfile is declared conform Servlet 3.0 specification (and thus not older, such as 2.5).Otherwise your container will run in a fallback modus matching the version matching in
web.xmlroot declaration, hereby losing all the new Servlet 3.0 and EL 2.2 awesomeness.The webapp’s
/WEB-INF/libdoes not contain container-specific EL implementation libraries originating from a container of an older make/version, such asel-api.jarand/orel-impl.jaroriginating from Tomcat 6.x or so.Your concrete problem is caused by using a non-Servlet 3.0 compatible container: the old Glassfish 2.x.
Upgrade to Glassfish 3.x or look for alternate ways. The JBoss EL approach works only for JSF, not for Spring nor “plain JSP”.