welcome-file index.xhtml将ExternalContext中的Not Found作为资源

时间:2017-03-19 22:05:03

标签: java jsf primefaces web.xml welcome-file

我有一个部署到wildfly 10服务器的jsf项目。部署之后,我导航到部署根(http://localhost:8080/ {deployment-name} /)获取" /home/default.xhtml在ExternalContext中找不到资源" 错误但是当我直接导航到web.xml中定义的文件为hello.xhtml(http://localhost:8080/ {deployment-name} /hello.xhtml)时,一切都很完美。 我猜这是一个错误的欢迎文件列表 我想知道如何将部署根目录转换为hello.xhtml? 提前致谢。 以下是源文件: web.xml:

 <?xml version="1.0" encoding="ISO-8859-1" ?>
    <web-app version="3.1" 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_3_1.xsd"

    >
      <display-name>Archetype Created Web Application</display-name>

    <listener><listener-class>com.sun.faces.config.ConfigureListener</listener-class></listener>
        <!-- JSF mapping -->
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>

        <!-- Map these files with JSF -->
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.xhtml</url-pattern>
        </servlet-mapping>
        <welcome-file-list>
            <welcome-file>/hello.xhtml</welcome-file>
        </welcome-file-list>
    </web-app>

,文件结构为:

-main
--java
--resources
--webapp 
---hello.xhtml
---WEB-INF
----web.xml
----templates
------default.xhtml

hello.xhtml文件是:

  <ui:composition xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:f="http://xmlns.jcp.org/jsf/core"
        xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
        xmlns:a4j="http://richfaces.org/a4j"
        xmlns:rich="http://richfaces.org/rich"
        template="/WEB-INF/templates/default.xhtml">
        <ui:define name="content">
        <f:view>

        <h2>This is content</h2>
        </f:view>
        </ui:define>
    </ui:composition>

和/WEB-INF/templates/default.xhtml是:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pretty="http://ocpsoft.com/prettyfaces"
      >
      <h:head>
      </h:head>
      <h:body>

       <div id="container">
        <div id="header">

        </div>
       <div id="content">
           <ui:insert name="content"></ui:insert>
       </div>
       <div id="footer">

       </div>
       </div>


        <div>

       </div>

      </h:body>
      </html>

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。它引起了漂亮的config.xml。系统找不到该文件中指示的资源文件。 pretty-config.xml

<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
                      http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">

     <url-mapping id="view-home">
    <pattern value="/" />
    <view-id value="/home/default.xhtml" />
</url-mapping>
<url-mapping id="view-user">
    <pattern value="/user/#{username}" />
    <view-id value="/user/view.xhtml" />
</url-mapping>
<url-mapping id="record-edit">
    <pattern value="/record/edit" />
    <view-id value="/xhtml/record/edit.xhtml" />
</url-mapping>

</pretty-config>

感谢每一个人。