第一步,,當(dāng)然是要將JSF的jar檔放對(duì)位置...
目錄/文件
|
說(shuō)明 |
Tutorial |
工程目錄
|
/ant |
ANT 腳本目錄,,默認(rèn)為 build.xml
|
/src |
Java 源文件, .properties 文件所在目錄,。
|
/public_html |
JSP/JSF 等動(dòng)態(tài)網(wǎng)頁(yè)所在目錄,。
|
/WEB-INF |
WEB應(yīng)用運(yùn)行時(shí)的配置文件、類庫(kù)等,,相對(duì)瀏覽器來(lái)說(shuō)不可見(jiàn),。
|
/classes |
Java源文件編譯后的輸出目錄。
|
/lib |
項(xiàng)目所依賴的類庫(kù),。
|
jsf-impl.jar jsf-api.jar |
JSF 1.1 的類庫(kù),,當(dāng)然還有一些Jakarta Common類庫(kù)的jar檔!
|
web.xml |
WEB應(yīng)用部署的配置文件
|
faces-config.xml |
JSF配置文件 |
pages |
JSP,、JSF和HTML
| 然后,,修改web.xml,請(qǐng)注意,,如果web.xml的格式為 version="2.4" 的話,,是不需要顯示指定taglib使用的tld文件的...我們只需要增加與JSF Servlet相關(guān)的定義:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java./xml/ns/j2ee" xmlns:xsi="http://www./2001/XMLSchema-instance" xsi:schemaLocation="http://java./xml/ns/j2ee http://java./xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <description>J2EE Tutorial Project</description> <display-name>Tutorial</display-name> <session-config> <session-timeout>30</session-timeout> </session-config> <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>*.faces</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> | 然后,在/WEB-INF下面新增faces-config.xml,,內(nèi)容如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java./dtd/web-facesconfig_1_1.dtd"> <faces-config xmlns="http://java./JSF/Configuration"> <managed-bean> <managed-bean-name>userBean</managed-bean-name> <managed-bean-class>tutorial.beans.UserBean</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <managed-property> <property-name>username</property-name> <property-class>java.lang.String</property-class> <value>Shark Wang</value> </managed-property> </managed-bean> <navigation-rule> <from-view-id>/pages/login.jsp</from-view-id> <navigation-case> <from-outcome>greeting</from-outcome> <to-view-id>/pages/greeting.jsp</to-view-id> </navigation-case> </navigation-rule> </faces-config>
| 完成上面的步驟后,,JSF并不會(huì)自動(dòng)啟動(dòng)起來(lái),,我們需要一個(gè)jsp來(lái)啟動(dòng)JSF...index.jsp代碼如下:
<%@page pageEncoding="UTF-8"%> <jsp:forward page="/pages/login.faces" /> | 開(kāi)始運(yùn)行...發(fā)現(xiàn)遇到一個(gè)很暈的錯(cuò)誤...就是:
ApplicationDispatcher[/Tutorial]: Servlet.service() for servlet Faces Servlet threw exception java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:140) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87) at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
| 原來(lái),,JSF還依賴于JSTL啊~~~也不見(jiàn)JSF文檔中有提啊...郁悶,加入JSTL的jstl.jar和standard.jar后就一切OK了,!
|