Servlets 无法识别JSF欢迎文件

Servlets 无法识别JSF欢迎文件,servlets,jsf-2,jetty,maven-jetty-plugin,Servlets,Jsf 2,Jetty,Maven Jetty Plugin,访问 http://localhost:8080/basicSetup/faces/index.xhtml 工作,输出: 你好,世界!金伟业 但是访问 http://localhost:8080/basicSetup 显示 你好,世界#{myBean.value} 这意味着欢迎文件不会呈现为JSF文件 我想要http://localhost:8080/basicSetup与访问http://localhost:8080/basicSetup/faces/index.xhtml 请分享你的想法

访问

http://localhost:8080/basicSetup/faces/index.xhtml
工作,输出:

你好,世界!金伟业

但是访问

http://localhost:8080/basicSetup
显示

你好,世界#{myBean.value}

这意味着欢迎文件不会呈现为JSF文件

我想要
http://localhost:8080/basicSetup
与访问
http://localhost:8080/basicSetup/faces/index.xhtml

请分享你的想法

JettyMaven插件:8.0.3.v20111011:run+JDK7+EclipseIndigo

这是我的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>

基本设置Web应用程序
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
/面孔/*
faces/index.xhtml
com.sun.faces.config.ConfigureListener
javax.faces.PROJECT_阶段
发展
这是jetty maven插件的输出:

[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 SelectChannelConnector@0.0.0.0:8080 STARTING
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 10 seconds.
jetty maven插件:8.0.3.v20111011:run(默认cli)@BasicSetup>> [信息] [信息]---maven资源插件:2.4.3:资源(默认资源)@BasicSetup--- [警告]使用平台编码(实际上是Cp1252)复制过滤后的资源,即构建依赖于平台! [信息]正在复制0资源 [信息] [信息]---maven编译器插件:2.3.2:compile(默认编译)@BasicSetup--- [信息]无需编译-所有类都是最新的 [信息] [信息]---maven资源插件:2.4.3:testResources(默认testResources)@BasicSetup--- [警告]使用平台编码(实际上是Cp1252)复制过滤后的资源,即构建依赖于平台! [信息]跳过不存在的资源目录C:\Users\albert\workspace\BasicSetup\src\test\resources [信息] [信息]---maven编译器插件:2.3.2:testCompile(默认testCompile)@BasicSetup--- [信息]没有要编译的源 [信息] [INFO]假定
表示文件的名称,该文件默认在请求文件夹时加载

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

如果您使用的是JSF2.x,那么我建议将
/faces/*
URL模式替换为
*.xhtml
,这样上面的方法就可以了,您就不需要再处理URL中的
/faces
路径了。或者,如果您使用的是JSF1.x,然后我建议用
*.jsf
替换
/faces/*
URL模式,并在文件夹中的
index.xhtml
旁边提供一个空的
index.jsf
文件,以欺骗容器该文件确实存在。

为了简单起见,我完全同意您的想法,在我的JSF2.x中只使用xhtml。我只是对我的例子中的问题感到好奇,因为在欢迎文件中使用文件夹路径的例子在核心JSF2书中有,嗯,你说得对,它在Tomcat和Glassfish上是这样工作的。实际上,我从未使用过
/faces/*
,我一直认为
应该引用磁盘上的物理文件,这也是规范所说的。也许那些容器在欢迎文件上自动检测到与前缀映射的servlet的匹配?我自己也从未使用过Jetty,但从我所读到的内容来看,Jetty有时非常有车而且很疯狂。谢谢!为了更通用的方法,我们将切换到*.xhtml,并考虑再次切换到tomcat7