将faces-config.xml添加到Web项目结果到RES_NOT_FOUND

时间:2014-08-30 07:43:02

标签: google-app-engine jsf

当我在我的项目中在WEB-INF中添加faces-config.xml文件时,我很奇怪它会导致错误“RES_NOT_FOUND” 注意:我试过<link type="text/css" rel="stylesheet" href="style.css" /> 没有faces-config.xml,它工作正常。我也尝试将其移到 resources 文件夹

我尝试使用此代码为我的.xhtml页面添加css文件

<h:head>
  <h:outputStylesheet name="styles.css" />
</h:head>

它将生成以下

<link type="text/css" rel="stylesheet" href="RES_NOT_FOUND">

我正在使用JSF 2.2 + Google App Engine,因为我遵循本网站的教程

http://java.wildstartech.com/Java-Platform-Enterprise-Edition/JavaServer-Faces/javaserver-faces-22/configuring-jsf-22-to-run-on-the-google-app-engine-using-eclipse

除了我尝试导入.css,.js和图像文件之类的外部文件之外,该教程很顺利;当我直接从像localhost:8080 / style.css这样的链接访问它时,css文件将正确显示。

这是我的代码

web.xml

<?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 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-app_2_5.xsd">
        <display-name>
            My App
        </display-name>
        <description>
            Template JSF 2.2 application configured to run on the Google
            AppEngine for Java.
        </description>
        <!-- ***** Designate client-side state saving. *****  -->
        <context-param>
            <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
            <param-value>client</param-value>
        </context-param>
        <!-- Set the default suffix for JSF pages to .xhtml -->
        <context-param>
            <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
            <param-value>.xhtml</param-value>
        </context-param>
        <!-- Disable use of threading for single-threaded environments such as the Google AppEngine. -->
        <context-param>
            <param-name>com.sun.faces.enableThreading</param-name>
            <param-value>false</param-value>
            <!--        <description>
                When enabled, the runtime initialization and default ResourceHandler 
                implementation will use threads to perform their functions. Set this 
                value to false if threads aren't desired (as in the case of running 
                within the Google Application Engine).

                Note that when this option is disabled, the ResourceHandler will not 
                pick up new versions of resources when ProjectStage is development.
            </description>-->
        </context-param>
        <!-- ***** Specify JBoss Expression Language Over Default -->
        <context-param>
            <param-name>com.sun.faces.expressionFactory</param-name>
            <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
        </context-param>
        <!-- ***** Load the JavaServer Faces Servlet ***** -->
        <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>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>faces/index.xhtml</welcome-file>
        </welcome-file-list>
        <context-param>
            <param-name>primefaces.UPLOADER</param-name>
            <param-value>commons</param-value>
        </context-param>
        <context-param>
            <param-name>javax.faces.CONFIG_FILES</param-name>
            <param-value>/WEB-INF/faces-config1.xml</param-value>
        </context-param>
        <filter>
            <filter-name>PrimeFaces FileUpload Filter</filter-name>
            <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
            <init-param>
                <param-name>thresholdSize</param-name>
                <param-value>2147483647</param-value>
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>PrimeFaces FileUpload Filter</filter-name>
            <servlet-name>Faces Servlet</servlet-name>
        </filter-mapping>
        <context-param>
            <param-name>javax.faces.PROJECT_STAGE</param-name>
            <param-value>Development</param-value>
        </context-param>
    </web-app>

index.xhtml

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <f:facet name="first">
            <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
            <title>There is Hope!</title>
        </f:facet>
        <h:outputStylesheet name="style.css" />
    </h:head>
    <h:body>
        <h:graphicImage url="logo.png"/>//this line works!
        <br />
        Hello from Facelets
        <br />
        <h:link outcome="welcomePrimefaces"  value="Primefaces welcome page" />
    </h:body>
</html>

appengine-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"
                   xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
                   xsi:schemaLocation='http://kenai.com/projects/nbappengine/downloads/download/schema/appengine-web.xsd appengine-web.xsd'>
    <application>RetailSmarts</application>
    <version>1</version>


    <!--Allows App Engine to send multiple requests to one instance in parallel:-->
    <threadsafe>true</threadsafe>

    <!-- Configure java.util.logging -->
    <system-properties>
        <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
    </system-properties>
    <sessions-enabled>true</sessions-enabled>
    <async-session-persistence enabled="true"></async-session-persistence>

</appengine-web-app>

faces-config.xml(没有这个我的web项目工作正常,但我打算稍后将它用于这些What is the use of faces-config.xml in JSF 2?

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" 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_2.xsd">
    <application>
        <lifecycle>
            <phase-listener>package.SessionPhaseListener</phase-listener>
        </lifecycle>
    </application>
</faces-config>

SessionPhaseListener.java

public class SessionPhaseListener implements PhaseListener, Serializable {

    private static final long serialVersionUID = 1L;

    @Override
    public void afterPhase(PhaseEvent arg0) {
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("CURRENT_TIME", System.currentTimeMillis());
    }

    @Override
    public void beforePhase(PhaseEvent arg0) {
    }

    @Override
    public PhaseId getPhaseId() {
        return PhaseId.ANY_PHASE;
    }
}

教程声明我需要添加PhaseListener以确保HttpSession的内容被保存

任何人都可以指出我的项目的哪个部分导致错误。我真的想使用faces-config.xml而不会出错。我的重点是,我无法导入我的项目中存在faces-config.xml的css,js和其他文件。是否有任何我为JSF和GAE设置错过的配置或信息。

0 个答案:

没有答案