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

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

问题描述

我在我的项目中使用了以下内容: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: 函数测试必须与未指定默认命名空间时的前缀

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.

我仅限于使用上面列出的一组技术,因此我无法添加任何内容,或者无法更改我的应用服务器的版本.

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:未指定默认命名空间时,必须使用带有前缀的函数测试

这表明环境不支持使用参数调用 bean 方法的新 EL 2.2 特性.过时的环境试图将表达式解释为具有符号 namespace:functionName() 的 EL 函数(类似于 JSTL 函数).例外只是抱怨无法找到 namespace: 部分以识别 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 根声明中的版本匹配相匹配的后备模式运行,从而失去所有新的 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.

Web 应用程序的 /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:未指定默认命名空间时,必须使用带有前缀的函数测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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