0

我有一个部署到 wildfly 10 服务器的 jsf 项目。部署后,我导航到部署根目录 ( http://localhost:8080/ {deployment-name}/) 得到“/home/default.xhtml Not Found in ExternalContext as a Resource”错误,但是当我直接导航到文件定义的文件时在 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>
4

1 回答 1

0

我解决了这个问题。这是 pretty-config.xml 引起的。系统未找到该文件中指示的资源文件。漂亮的配置.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>

感谢每一个人。

于 2017-03-20T05:55:15.227 回答