轉自:http://blog.knowsky.com/260578.htmjava
問題出現:web
嚴重: Exception starting filter struts2
java.lang.ClassNotFoundException: prg.apache.struts2.dispatcher.FilterDispatcher
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1666)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1511)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:406)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:388)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:117)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:248)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:368)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:98)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4193)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4801)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:988)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:771)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:988)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:275)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:427)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:649)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.startup.Catalina.start(Catalina.java:585)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:415)
2010-12-1 13:10:06 org.apache.catalina.core.StandardContext startInternal
嚴重: Error filterStart
2010-12-1 13:10:06 org.apache.catalina.core.StandardContext startInternal
嚴重: Context [/struts2] startup failed due to previous errorsapache
解決方法:api
很明顯的錯誤:java.lang.ClassNotFoundException: FilterDispatcher
找不到FilterDispatcher這個類(FilterDispatcher分發器,是Struts2框架的核心Dispatcher,沒有它,也就談不起Struts2框架)
首先:看看有沒有導入Struts2相應的jar包,是否齊全。最少要導入五個基本包:
commons-logging-api-1.1.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
struts2-core-2.0.12.jar
xwork-2.0.6.jar
若是該包含的jar包都引入了,再看,配置文件web.xml是否配置正確,
struts2使用的是Filter充當Control 須要配置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>*.do</url-pattern>
<!-- 這裏的url-pattern視你的具體狀況而定-->
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/struts/*</url-pattern>
</filter-mapping>
若是以上兩步都沒有問題,那估計就是環境問題了,在開發中,環境問題是麻煩的事,檢查你用的部署服務器(Tomcat或weblogic等)、IDE的版本(eclipse或者myEclipse),以及Struts2的版本...
struts2項目中web.xml配置2.1與2.0的區別
具體的過濾器類變了,2.0配置是以上寫法
2.1之後是這樣配置
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>服務器
另外,也與你導入jar包的位置有關,建議最好放入工程WEB-INF下的lib目錄的根目錄裏,不然有時不能識別。app
文章來自百度!框架