【问题标题】:welcome-file index.xhtml gives Not Found in ExternalContext as a ResourceWelcome-file index.xhtml 将 Not Found in ExternalContext 作为资源
【发布时间】:2017-08-11 02:20:09
【问题描述】:

我有一个部署到 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>

【问题讨论】:

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


    【解决方案1】:

    我解决了这个问题。这是 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>
    

    感谢每一个人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-11
      • 1970-01-01
      • 2016-02-10
      • 1970-01-01
      • 2013-07-30
      • 2016-12-25
      • 1970-01-01
      • 2020-11-28
      相关资源
      最近更新 更多