EL表达式不在JSF的JSP页面中求值 [英] EL expressions are not evaluated in JSP page of JSF

查看:104
本文介绍了EL表达式不在JSF的JSP页面中求值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的inputname.jsp文件

My inputname.jsp file

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> 
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> 

<html> 
<head> 
<title>enter your name page</title> 
</head> 
<body> 
<f:view> 
<h1> 
<h: outputText value="JSF 1.2 Tutorial"/> 
</h1> 
<h:form id="UserEntryForm"> 
<h: outputText value="Enter Your Name:"/> 
<h:inputText value="#{UserBean.userName}" /> 
<h:commandButton action="welcome" value="OK" /> 
</h:form> 
</f:view> 
</body> 
</html> 

My welcome.jsp file 
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> 
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> 
<html> 
<head> 
<title>Welcome</title> 
</head> 
<body> 
<f:view> 
<h3> 
<h: outputText value="Welcome" />, 
<hutputText value="#{UserBean.userName}" /> to JSF 1.2 World! 
</h3> 
</f:view> 
</body> 
</html> 

我的web.xml文件

my web.xml file

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE web-app PUBLIC 
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
"http://java.sun.com/dtd/web-app_2_3.dtd"> 


<web-app> 

<!-- Faces Servlet --> 
<servlet> 
<servlet-name>Faces Servlet</servlet-name> 
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
<load-on-startup> 1 </load-on-startup> 
</servlet> 

<!-- Faces Servlet Mapping --> 
<servlet-mapping> 
<servlet-name>Faces Servlet</servlet-name> 
<url-pattern>*.jsf</url-pattern> 
</servlet-mapping> 

</web-app> 

我的面孔配置文件

<?xml version='1.0' encoding='UTF-8'?> 

<!DOCTYPE faces-config PUBLIC 
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" 
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd"> 

<faces-config> 

<navigation-rule> 
<from-view-id>/user/inputname.jsp</from-view-id> 
<navigation-case> 
<from-outcome>welcome</from-outcome> 
<to-view-id>/user/welcome.jsp</to-view-id> 
</navigation-case> 
</navigation-rule> 
<managed-bean> 
<managed-bean-name>UserBean</managed-bean-name> 
<managed-bean-class>net.roseindia.UserNameBean</managed-bean-class> 
<managed-bean-scope>request</managed-bean-scope> 
</managed-bean> 

</faces-config> 

我的UserNameBean.java文件

my UserNameBean.java file

package net.roseindia; 

public class UserNameBean { 

String userName; 

/** 
* @return User Name 
*/ 
public String getUserName() { 
return userName; 
} 

/** 
* @param User Name 
*/ 
public void setUserName(String name) { 
userName = name; 
} 
} 

当我打开inputname.jsf时我得到

when i open inputname.jsf i get

Enter your name: #{UserBean.userName} 

而不是评估userbean.username而是打印它 同样在welcome.jsf上发生 我得到欢迎使用#{UserBean.userName}进入JSF 1.2 World!

instead of evaluating userbean.username it is just printing it same happens at welcome.jsf i get Welcome, #{UserBean.userName} to JSF 1.2 World!

我在做什么错 请帮忙 克里山

what am i doing wrong Please help Krishan

推荐答案

在JSP上使用JSF 1.2需要最少的Servlet 2.5容器,因为EL发生了变化(EL已从JSF 1.1移至JSP 2.1,这是一部分Servlet 2.5).您需要确保在具有web.xml的Servlet 2.5兼容容器上运行JSF 1.2 webapp,该容器声明为符合Servlet 2.5规范(或更好的是,容器支持的最大值).您的web.xml是根据Servlet 2.3声明的,它表示不同的EL版本,因此将不评估EL表达式.

Using JSF 1.2 on JSP requires a minimum of Servlet 2.5 container because of the changes in EL (EL has been moved from JSF 1.1 to JSP 2.1, which is part of Servlet 2.5). You need to ensure that you're running your JSF 1.2 webapp on a Servlet 2.5 compatible container with a web.xml which is declared conform the Servlet 2.5 specification (or better, the maximum whatever your container supports). Your web.xml is declared as per Servlet 2.3 which implies a different EL version and hence EL expressions won't be evaluated.

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

    <!-- Config here. -->

</web-app>

请注意,您的faces-config.xml被错误地声明为JSF 1.1.您想将其重新声明为JSF 1.2,以充分利用JSF 1.2的功能.

Note that your faces-config.xml is incorrectly declared as JSF 1.1. You'd like to redeclare it as JSF 1.2 to fully utilize the JSF 1.2 features.

<?xml version="1.0" encoding="UTF-8"?>
<faces-config 
    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-facesconfig_1_2.xsd"
    version="1.2">

    <!-- Config here. -->

</faces-config>

最后但并非最不重要的是, Roseindia.net是Java EE的 WORST 学习资源之一.您应该将该站点真正列入黑名单.寻找其他学习资源.检查 https://stackoverflow.com/tags/jsf/info

Last, but not least, Roseindia.net is one of the WORST learning resources for Java EE. You should really put that site in your blacklist. Look for a different learning resource. Check the "Resources" section of https://stackoverflow.com/tags/jsf/info

这篇关于EL表达式不在JSF的JSP页面中求值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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