org.apache.jasper.JasperException:当未指定默认命名空间时,函数test必须与前缀一起使用 [英] org.apache.jasper.JasperException: The function test must be used with a prefix when a default namespace is not specified

查看:217
本文介绍了org.apache.jasper.JasperException:当未指定默认命名空间时,函数test必须与前缀一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的项目使用以下内容:
Spring 3.0.1 + Apache Tiles 2.2.1 + Glassfish 2.1。我想要做的是在jsp页面中调用一些方法并将一些参数传递给它。例如,我有一个bean:

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

我有一个jsp页面:

<%@page contentType="text/html; charset=utf-8"%>
${testBean.test("hello")}

这段代码给了我一个例外喜欢:

This code gives me an exception like:


org.apache.jasper.JasperException:当默认命名空间不是
a前缀时,函数测试必须使用指定

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.

我试图将jboss-el.jar放入我的WEB-INF / lib并将所需参数放入web.xml中(如其他),但没有效果。

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.

我仅限于上面列出的一组技术,因此我无法添加任何内容,或者,例如,无法更改我的app-server的版本。

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?

推荐答案


org.apache.jasper.JasperException:当未指定默认命名空间时,函数test必须与前缀一起使用

这表明环境不支持使用参数调用bean方法的新EL 2.2功能。过时的环境试图将表达式解释为EL函数,该函数具有符号 namespace:functionName()(与JSTL函数一样)。唯一的例外是抱怨命名空间:部分无法找到以识别EL功能。但毕竟这是错误的。

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 that namespace: part cannot be found in order to identify the EL function. But it is wrong, after all.

您需要确保满足以下条件才能在EL中使用参数调用bean方法:

You need to ensure that the following conditions are met in order to be able to invoke bean methods with arguments in EL:


  1. 目标容器必须支持EL 2.2。所有与Servlet 3.0兼容的容器都可以,因为EL 2.2是Java EE 6的一部分,而Java EE 6又包含Servlet 3.0。 Servlet 3.0容器的示例是Tomcat 7.x,Glassfish 3.x和JBoss AS 6.x / 7.x。

  1. 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.

/WEB-INF/web.xml 文件声明符合Servlet 3.0规范(因此不是较旧的,如2.5)。

The /WEB-INF/web.xml file is declared conform Servlet 3.0 specification (and thus not older, such as 2.5).

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <!-- Config here. -->

</web-app>

否则您的容器将以与 web中匹配的版本匹配的后备模式运行.xml root声明,因此丢失了所有新的Servlet 3.0和EL 2.2非常棒。

Otherwise your container will run in a fallback modus matching the version matching in web.xml root declaration, hereby losing all the new Servlet 3.0 and EL 2.2 awesomeness.

webapp的 / WEB-INF / lib 包含源自旧版本/版本容器的特定于容器的EL实现库,例如 el- api.jar 和/或 el-impl.jar 来自Tomcat 6.x左右。

The webapp's /WEB-INF/lib does not contain container-specific EL implementation libraries originating from a container of an older make/version, such as el-api.jar and/or el-impl.jar originating from Tomcat 6.x or so.

您的具体问题是由使用非Servlet 3.0兼容容器引起的:旧的Glassfish 2.x.

Your concrete problem is caused by using a non-Servlet 3.0 compatible container: the old Glassfish 2.x.

升级到 Glassfish 3.x 或寻找备用方法。 JBoss EL方法仅适用于JSF,不适用于Spring,也不适用于普通JSP。

Upgrade to Glassfish 3.x or look for alternate ways. The JBoss EL approach works only for JSF, not for Spring nor "plain JSP".

这篇关于org.apache.jasper.JasperException:当未指定默认命名空间时,函数test必须与前缀一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆