我開始實現一個非常基本的JSF應用程序,但我無法打印的JSF託管Bean消息的HTML ..JSF樣本項目管理豆錯誤,不能打印管理豆消息的HTML
這裏是我的代碼:
HelloWorld.java:
package com.project.managedbeans;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean(name="helloWorld", eager=true)
@RequestScoped
public class HelloWorld {
private String message;
public HelloWorld(){
System.out.println("Hello World Managed Bean is created");
}
public String getMessage(){
return "Hello World ! ";
}
public void setMessage(String message){
this.message = message;
}
的index.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<body>
#{helloWorld.message}
</body>
</html>
faces-config.xml中
<?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_2_1.xsd"
version="2.1">
</faces-config>
和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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>jsfSampleProject</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>
,當我運行Apache服務器上的應用程序,該頁面下
本地主機,我看到:8080/jsfSampleProject /是:
#{} helloWorld.message
我Librar下JSF 2.1 Mojorra ies選項卡。你認爲問題是什麼?
謝謝。
你得到了什麼錯誤?你在使用Netbeans嗎? – 2013-05-04 13:24:08
我正在使用Eclipse IDE,我添加了錯誤問題,我得到了#{helloWorld.message}而不是Hello World! – KarmicKoala86 2013-05-04 13:29:41
更改爲@SessionScope,讓我知道你得到了什麼。(我知道這不是一個問題) – 2013-05-04 13:36:48