不评估EL表达式

时间:2011-05-31 12:59:40

标签: java jsp jsf el

我开发了一个java服务器页面,它有java服务器面部标签。它正在获取这样的bean数据:

<h:inputText value="#{UserBean.userName}" />

但是当我运行它时,它显示的是值,而不是评估值。

这是如何引起的?如何解决?

3 个答案:

答案 0 :(得分:3)

那么,EL表达式不会被评估,你会在网页中看到#{UserBean.userName}而不是评估值吗?

确保声明web.xml符合webcontainer支持的最大受支持Servlet版本。 JSF 1.2和2.0至少需要Servlet 2.5。 JSF 2.1至少需要Servlet 3.0。 Servlet版本与使用的EL版本耦合。 JSF 1.2 / 2.0依赖于新的“统一EL”(EL 2.1),它是Servlet 2.5的一部分。

我将假设Servlet 2.5,这里是web.xml的根声明应该如何:

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

    <!-- Your config here -->

</web-app>

如果您已将项目正确配置为Servlet 2.5项目并选择了Servlet 2.5兼容容器(例如至少Tomcat 6.0),那么有点像IDE可以为您自动生成它。

答案 1 :(得分:0)

我猜你在web.xml中缺少JSF servlet。

以下是JSF 2.0的示例配置:

<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_2_5.xsd"
    version="2.5">

    <description>JSF 2.0 - Hello World</description>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <!-- This is important -->
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <!-- This is important -->
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>hello.xhtml</welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
</web-app>

您可能需要为JSF 1.2添加一些额外的servlet,这里是example for RichFaces。请验证您的web.xml是否至少包含FacesServlet以及是否正确完成了servlet映射。如果您需要更多帮助,请粘贴web.xml和faces-config.xml(如果存在)。

答案 2 :(得分:0)

除了servlet版本(从2.5开始)之外,不要忘记查看web.xml中是否有el-ignored为true。

<jsp-config> 
   <jsp-property-group> 
   <url-pattern>*.jsp</url-pattern> 
   <el-ignored>true</el-ignored> 
   </jsp-property-group 
</jsp-config>

或页面中的JSP指令如下:

<%@ page isELIgnored="true" %>