【问题标题】:Error: /JavaServerFaces/default.xhtml Not Found in ExternalContext as a Resource错误:在 ExternalContext 中找不到 /JavaServerFaces/default.xhtml 作为资源
【发布时间】:2016-04-10 20:15:10
【问题描述】:

我从 jsf-spring 集成开始。我通过从link 下载一个 jsf-spring 集成示例来学习并尝试运行。当我浏览器http://http://localhost:8080/JavaServerFaces/default.xhtml 时出现上述错误。我真的不明白为什么???我调整以在pom.xml 中添加码头插件。请告诉我。

这里是pom.xml中添加的部分

<build>
        <finalName>JavaServerFaces</finalName>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12.4</version>
            <configuration>
                <skipTests>true</skipTests>
                <argLine>-Xmx2524m</argLine>
            </configuration>
        </plugin>


        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.3.0.M1</version>
                <configuration>
                    <jvmArgs>-Xmx1048m -Xms536m
                        -XX:PermSize=128m -XX:MaxPermSize=512m</jvmArgs>
                    <reload>manual</reload>
                    <systemProperties>
                        <systemProperty>
                            <name>lib</name>
                            <value>${basedir}/target/spring-mvc/WEB-INF/lib</value>
                        </systemProperty>
                    </systemProperties>
                    <scanIntervalSeconds>3</scanIntervalSeconds>
                    <connectors>
                        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                            <port>8080</port>
                            <maxIdleTime>60000</maxIdleTime>
                        </connector>
                    </connectors>
                    <contextPath>/</contextPath>
                    <webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory>
                    <webXml>${basedir}/src/main/webapp/WEB-INF/web.xml</webXml>
                    <classesDirectory>${basedir}/target/classes</classesDirectory>
                </configuration>
            </plugin>

        </plugins>
    </build>

这里是web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    id="WebApp_ID" version="2.5">

  <display-name>JavaServerFaces</display-name>

  <!-- Add Support for Spring -->
  <listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>
  <listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
  </listener>

  <!-- Change to "Production" when you are ready to deploy -->
  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
  </context-param>

  <!-- Welcome page -->
  <welcome-file-list>
    <welcome-file>default.xhtml</welcome-file>
  </welcome-file-list>

  <!-- JSF Mapping -->
  <servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>

</web-app>

【问题讨论】:

  • 分享您的 web.xml 文件
  • @SubodhJoshi,我在帖子中添加了 web.xml 文件
  • 你试过扩展 *.jsf 吗?
  • 这应该没什么区别。异常表明 Maven 构建或 Jetty 配置错误。 Maven 没有正确地将 XHTML 文件放入 WAR 文件中,或者 Jetty 没有配置为在部署中包含来自 WAR 的 XHTML 文件。这不是 JSF 问题。
  • 感谢@BalusC 解决问题

标签: spring maven jsf jetty


【解决方案1】:

我已经解决了我的问题。我必须浏览http://localhost:8080/default.xhtml 而不是http://localhost:8080/JavaServerFaces/default.xhtml。因为在码头的插件中,我配置了context path/ 而不是/JavaServerFaces。多谢@BalusC :)

【讨论】:

    猜你喜欢
    • 2012-10-20
    • 1970-01-01
    • 2013-11-11
    • 1970-01-01
    • 2011-10-09
    • 2021-06-02
    • 2016-02-10
    • 1970-01-01
    • 2015-01-01
    相关资源
    最近更新 更多