搭建struts2環境,在web.xml中加入過濾器的代碼後通路任何頁面都是404錯誤。請大家幫幫忙。
我是用myeclipse做的,我的步驟是這樣的:
1、建立web project項目。
2、導入struts2.3.8的必須庫類。類庫檔案如下:

3:釋出web 工程,我用的是tomcat 7.x。
(這時候我通路工程中的index.jsp可以正常通路)
4、編輯項目檔案夾目錄WebRoot\WEB-INF下的web.xml。在代碼中加入過濾器的代碼。
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
如下圖:
儲存好。
這時候控制台輸出如下資訊:(省略了部分)
2013-3-5 13:13:04 org.apache.catalina.startup.HostConfig checkResources
資訊: Reloading context [/C04]
2013-3-5 13:13:04 org.apache.catalina.core.StandardContext reload
資訊: Reloading Context with name [/C04] has started
2013-3-5 13:13:07 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
資訊: Parsing configuration file [struts-default.xml]
2013-3-5 13:13:07 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
資訊: Parsing configuration file [struts-plugin.xml]
2013-3-5 13:13:07 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
嚴重: Dispatcher initialization failed
Unable to load configuration. - bean - jar:file:/C:/Program%20Files/apache-tomcat-
2013-3-5 13:13:07 org.apache.catalina.core.StandardContext startInternal
嚴重: Error filterStart
2013-3-5 13:13:07 org.apache.catalina.core.StandardContext startInternal
嚴重: Context [/C04] startup failed due to previous errors
2013-3-5 13:13:07 org.apache.catalina.core.StandardContext reload
資訊: Reloading Context with name [/C04] is completed
5、這時候通路工程的index.jsp就是404錯誤。不能通路,如果在web.xml中删除以下過濾器的代碼
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
可以正常通路index.jsp。
暫時知道解決方案:
是少了一個jar包,但是不知道少了哪個包???