2011-10-25 124 views
5

訪問JSF歡迎文件不被識別

http://localhost:8080/basicSetup/faces/index.xhtml 

作品,與輸出:

的Hello World!阿爾伯特·錦

但訪問

http://localhost:8080/basicSetup 

顯示

的Hello World! #{} myBean.value

意思是歡迎文件不會被渲染爲JSF文件

我想http://localhost:8080/basicSetup有作爲訪問http://localhost:8080/basicSetup/faces/index.xhtml同樣的效果。

請分享你的想法

碼頭 - Maven的插件:8.0.3.v20111011:運行+ JDK 7 +日食靛藍

這裏是我的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"> 
    <display-name>Basic Setup Web Application</display-name> 
    <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>faces/index.xhtml</welcome-file> 
    </welcome-file-list> 
    <listener> 
     <listener-class> 
      com.sun.faces.config.ConfigureListener 
     </listener-class> 
    </listener> 
    <context-param> 
     <param-name>javax.faces.PROJECT_STAGE</param-name> 
     <param-value>Development</param-value> 
    </context-param> 
</web-app> 

這就是碼頭行家插件輸出:

[INFO] >>> jetty-maven-plugin:8.0.3.v20111011:run (default-cli) @ BasicSetup >>> 
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ BasicSetup --- 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] Copying 0 resource 
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ BasicSetup --- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ BasicSetup --- 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] skip non existing resourceDirectory C:\Users\albert\workspace\BasicSetup\src\test\resources 
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ BasicSetup --- 
[INFO] No sources to compile 
[INFO] 
[INFO] <<< jetty-maven-plugin:8.0.3.v20111011:run (default-cli) @ BasicSetup <<< 
[INFO] 
[INFO] --- jetty-maven-plugin:8.0.3.v20111011:run (default-cli) @ BasicSetup --- 
[INFO] Configuring Jetty for project: BasicSetup Maven Webapp 
[INFO] webAppSourceDirectory C:\Users\albert\workspace\BasicSetup\src\main\webapp does not exist. Defaulting to C:\Users\albert\workspace\BasicSetup\src\main\webapp 
[INFO] Reload Mechanic: automatic 
[INFO] Classes = C:\Users\albert\workspace\BasicSetup\target\classes 
[INFO] Context path = /basicSetup 
[INFO] Tmp directory = C:\Users\albert\workspace\BasicSetup\target\tmp 
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml 
[INFO] Web overrides = none 
[INFO] web.xml file = file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/WEB-INF/web.xml 
[INFO] Webapp directory = C:\Users\albert\workspace\BasicSetup\src\main\webapp 
2011-10-25 14:03:59.073:INFO:oejs.Server:jetty-8.0.3.v20111011 
2011-10-25 14:03:59.333:INFO:oejpw.PlusConfiguration:No Transaction manager found - if your webapp requires one, please configure one. 
2011-10-25 14:04:00.104:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/basicSetup,[file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/, jar:file:/C:/Users/albert/.m2/repository/org/glassfish/javax.faces/2.1.3/javax.faces-2.1.3.jar!/META-INF/resources/]},file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/ 
2011-10-25 14:04:00.104:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/basicSetup,[file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/, jar:file:/C:/Users/albert/.m2/repository/org/glassfish/javax.faces/2.1.3/javax.faces-2.1.3.jar!/META-INF/resources/]},file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/ 
2011-10-25 14:04:00.104:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/basicSetup,[file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/, jar:file:/C:/Users/albert/.m2/repository/org/glassfish/javax.faces/2.1.3/javax.faces-2.1.3.jar!/META-INF/resources/]},file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/ 
Oct 25, 2011 2:04:00 PM com.sun.faces.config.ConfigureListener contextInitialized 
INFO: Initializing Mojarra 2.1.3 (SNAPSHOT 20110908) for context '/basicSetup' 
Oct 25, 2011 2:04:00 PM com.sun.faces.spi.InjectionProviderFactory createInstance 
INFO: JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed. 
Oct 25, 2011 2:04:00 PM com.sun.faces.config.ConfigureListener$WebConfigResourceMonitor$Monitor <init> 
INFO: Monitoring file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/WEB-INF/faces-config.xml for modifications 
2011-10-25 14:04:00.787:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/basicSetup,[file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/, jar:file:/C:/Users/albert/.m2/repository/org/glassfish/javax.faces/2.1.3/javax.faces-2.1.3.jar!/META-INF/resources/]},file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/ 
2011-10-25 14:04:00.825:INFO:oejs.AbstractConnector:Started [email protected]:8080 STARTING 
[INFO] Started Jetty Server 
[INFO] Starting scanner at interval of 10 seconds. 

回答

12

<welcome-file>是SUPP提出代表文件文件的名稱,默認情況下每當文件夾被請求時加載。

<welcome-file>index.xhtml</welcome-file> 

如果你使用JSF 2.x的,那麼我建議由*.xhtml更換/faces/* URL模式,然後上面會工作,你不再需要在網址/faces路徑擺弄。或者,如果你使用JSF 1.x的話,我建議由*.jsf更換/faces/* URL模式,文件夾中提供一個空index.jsf文件旁邊index.xhtml愚弄該文件真的存在的容器。

+0

我完全同意你的想法只使用XHTML我JSF2.x.的簡單起見,同意我只是對我的情況很好奇,因爲在welcome-file中使用文件夾路徑的例子是http://netbeans.org/kb/docs/web/jsf20-intro.html和核心jsf 2書.. – bertie

+1

嗯,你是對的,它可以在Tomcat和Glassfish上工作。我實際上從來沒有使用'/ faces/*',我一直認爲''應該引用磁盤上的物理文件,這也是字面說明的規範。也許這些容器自動檢測與歡迎文件上的前綴映射servlet匹配?我自己也從來沒有使用Jetty,但從我讀到的是,它有時非常錯誤和瘋狂。 – BalusC

+0

謝謝!爲了更常見的做法,將切換到* .xhtml,並會考慮再次切換到tomcat7 – bertie