2011-06-06 59 views
1

我inputname.jsp文件EL表达式不被评估

<%@ 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文件

<?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> 

我的脸-config文件

<?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文件

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我得到

Enter your name: #{UserBean.userName} 

而不是评估userbean.username它只是在打印 同样发生在welcome.jsf 我得到欢迎,#{} UserBean.userName对JSF 1.2世界!

我在做什么错 请帮助 克尚

回答

3

在JSP中使用JSF 1.2至少需要Servlet的,因为变化2.5容器在EL中(EL已经从JSF 1.1移动到JSP 2.1,这是Servlet 2.5的一部分)。您需要确保您正在Servlet 2.5兼容容器上运行JSF 1.2 Web应用程序,其中的web.xml声明符合Servlet 2.5规范(或更好,无论您的容器支持哪种最高容量)。您的web.xml根据Servlet 2.3进行声明,这意味着不同的EL版本,因此不会评估EL表达式。

<?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功能。

<?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 is one of the WORST learning resources for Java EE。你应该把这个网站放在你的黑名单中。寻找不同的学习资源。虽然JSF 2.0的目标,我建议this tutorial和资源在Mkyong.com

0

添加正确的版本到你的web.xml

<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_4.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">