404 /index.xhtml在ExternalContext中找不到作为资源

时间:2017-01-26 01:02:47

标签: maven jsf war

我知道有与此主题相关的类似问题。但是,没有一个答案对我有帮助,我根本无法让我的Intellij / Tomcat正常运行。

Tomcat无法找到任何* .xhtml或纯HTML文件。每次我尝试从IntellIj运行项目时,我只是得到标题中提到的错误。我也尝试用maven部署项目。没有成功(同样的问题)。

我使用Xampp将Tomcat安装在Win10 64位计算机上的默认位置C:\ xampp中。以下是我的项目结构:

enter image description here

我在pom.xml和插件中定义了所有依赖项,以便在tomcat上部署Web应用程序:

   <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>${servlet.version}</version>
      <scope>provided</scope>
    </dependency>
    <!-- Mojarra JSF -->
    <dependency>
      <groupId>com.sun.faces</groupId>
      <artifactId>jsf-api</artifactId>
      <version>${mojarra.version}</version>
    </dependency>
    <dependency>
      <groupId>com.sun.faces</groupId>
      <artifactId>jsf-impl</artifactId>
      <version>${mojarra.version}</version>
    </dependency>
    <!-- PrimeFaces -->
    <dependency>
      <groupId>org.primefaces</groupId>
      <artifactId>primefaces</artifactId>
      <version>${primefaces.version}</version>
    </dependency>
    <dependency>
        <groupId>org.primefaces.extensions</groupId>
        <artifactId>all-themes</artifactId>
        <version>1.0.8</version>
    </dependency>

我在Intellij中为Tomcat配置的内容:Run/Debug settings in Intellij

我不知道这可能是什么。多次检查URL,丢弃web.xml中virtual / faces / *文件夹的声明。这是我的完整web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
    <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>*.xhtml</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
    <listener id="ServiceLocator">
        <display-name>InitializeContextListener</display-name>
        <listener-class>wuhu.webclient.InitializeContextListener</listener-class>
    </listener>


    <context-param>
        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>resources.application</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>WUHU_SERVICE_URL</param-name>
        <param-value>http://localhost:%s/wuhuservice</param-value>
    </context-param>
    <context-param>
        <param-name>WUHU_SERVICE_PORT</param-name>
        <param-value>8123</param-value>
    </context-param>
</web-app>

1 个答案:

答案 0 :(得分:1)

错误的Maven项目结构,由JimHawkins在评论中回答