无法识别 JSF 欢迎文件 [英] JSF welcome file is not recognized

查看:25
本文介绍了无法识别 JSF 欢迎文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

访问

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

有效,输出为:

世界你好!艾伯特·甘

但正在访问

http://localhost:8080/basicSetup

节目

世界你好!#{myBean.value}

Hello World ! #{myBean.value}

表示欢迎文件不会呈现为 JSF 文件

meaning that the welcome file is not rendered as a JSF file

我希望 http://localhost:8080/basicSetup 与访问 http://localhost:8080/basicSetup/faces/index.xhtml 具有相同的效果>.

I would like http://localhost:8080/basicSetup to have the same effect as accessing http://localhost:8080/basicSetup/faces/index.xhtml.

请分享您的想法

jetty-maven-plugin:8.0.3.v20111011:run + jdk 7 + eclipse indigo

jetty-maven-plugin:8.0.3.v20111011:run + jdk 7 + eclipse indigo

这是我的 web.xml 文件:

Here is my web.xml file :

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

这是码头 Maven 插件输出:

and this is the jetty maven plugin output :

[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:UsersalbertworkspaceBasicSetupsrc	est
esources
[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:UsersalbertworkspaceBasicSetupsrcmainwebapp does not exist. Defaulting to C:UsersalbertworkspaceBasicSetupsrcmainwebapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = C:UsersalbertworkspaceBasicSetup	argetclasses
[INFO] Context path = /basicSetup
[INFO] Tmp directory = C:UsersalbertworkspaceBasicSetup	arget	mp
[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:UsersalbertworkspaceBasicSetupsrcmainwebapp
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.

推荐答案

应该代表默认文件的文件名称每当请求文件夹时加载.

The <welcome-file> is supposed represent the file name of the file which is default to be loaded whenever a folder is been requested.

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

如果您使用的是 JSF 2.x,那么我建议将 /faces/* URL 模式替换为 *.xhtml,然后上述内容将起作用,您不再需要在 URL 中摆弄 /faces 路径.或者,如果您使用的是 JSF 1.x,那么我建议将 /faces/* URL 模式替换为 *.jsf 并提供一个空的 index.jsf 文件夹中 index.xhtml 旁边的文件,以欺骗容器该文件确实存在.

If you're using JSF 2.x, then I suggest to replace /faces/* URL pattern by *.xhtml, then the above will work and you do not need to fiddle with /faces paths in URLs anymore. Or, if you're using JSF 1.x, then I suggest to replace the /faces/* URL pattern by *.jsf and provide an empty index.jsf file next to index.xhtml in the folder to fool the container that the file really exist.

这篇关于无法识别 JSF 欢迎文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆