【问题标题】:I cannot access my simple jsf project after deployement部署后我无法访问我的简单 jsf 项目
【发布时间】:2013-04-06 15:05:00
【问题描述】:

我不明白为什么在尝试访问我的应用程序时出现 404 错误

我的 index.xhtml 在(网页内容)中

在我的日志中我没有错误 我使用 eclipse 创建了我的项目:web 动态项目:

我的网址:

http://localhost:8080/jsf_getting_started/

我尝试使用 eclipse 和 tomcat(在服务器上运行)。

我的网页 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_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>jsf_getting_started</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>


<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>/faces/*</url-pattern>
</servlet-mapping>
<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>
<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

【问题讨论】:

  • 这个罐子叫什么名字?默认 url 为“localhost:8080/name_of_jar”,不带后缀 .jar。 Url 与显示名称无关,而是在 context.xml 中定义的上下文。

标签: jsf tomcat deployment http-status-code-404


【解决方案1】:

问题是您已将 Faces Servlet 的映射设置为/faces/*,因此为了访问您的页面并被此 servlet 解析,您必须像访问它一样访问它

http://localhost:8080/jsf_getting_started/faces/index.xhtml

/faces/* 配置的问题在于,Faces Servlet 甚至会处理非 JSF 资源,如图像、JS、CSS 脚本等。

最好的解决方案是将映射更改为*.xhtml,并删除欢迎文件列表中的所有页面以仅包含index.xhtml。您的 web.xml 文件将如下所示(请注意,我只是发布对此答案中描述的部分所做的更改):

<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
    <!-- no need of the other files... -->
</welcome-file-list>

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <!-- The relevant URL mapping when using Facelets and JSF -->
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

更改 web.xml 文件后,重建您的项目,确保从 Tomcat 服务器取消部署,然后重试。

【讨论】:

    【解决方案2】:

    您需要在welcome-file-list 中添加index.xhtml

    【讨论】:

    • 它不起作用,我得到一个空白页,而我的索引包含:
    • 这取决于他的“家”文件名...不是每个人都将其命名为 index.xhtml。
    猜你喜欢
    • 1970-01-01
    • 2021-02-25
    • 1970-01-01
    • 2016-12-17
    • 2015-02-23
    • 2021-02-02
    • 2023-01-04
    • 1970-01-01
    • 2012-01-15
    相关资源
    最近更新 更多