【发布时间】:2015-06-22 13:38:47
【问题描述】:
我是 eclipse 的初学者,正在尝试一个简单的 Web 项目,从一个 hello world 页面开始。 但是当我在 tomcat 服务器上运行项目时,这个 url 被触发并且我得到 HTTP 404 错误:-
http://localhost:8080/TestWeb/
我的web.xml文件内容如下:-
<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>TestWeb</display-name>
<welcome-file-list>
<welcome-file>HelloWorld.xhtml</welcome-file>
<welcome-file>HelloWorld.xhtml</welcome-file>
<welcome-file>HelloWorld.xhtml</welcome-file>
<welcome-file>HelloWorld.xhtml</welcome-file>
<welcome-file>HelloWorld.xhtml</welcome-file>
<welcome-file>HelloWorld.xhtml</welcome-file>
</welcome-file-list>
<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>*.xhtml</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>
</web-app>
【问题讨论】:
-
您可以尝试以下方法:使用
/faces/* 添加一个 servlet-mapping 标记部分,同时使用faces/HelloWorld。 xhtml 在welcome-file-list 标记中。 -
'/faces/*' 等应该在现代 jsf 应用程序中不再需要(或使用)。而且由于现在 web.xml 中没有到 '/faces/* 的映射,所以它也不会导致问题。所以宁可询问/查询jsf版本等......
-
@Rin:请停止发布废话。最好尝试自己重现和解决问题,以便您可以从经验中学习。
标签: eclipse jsf tomcat facelets welcome-file