严重: Exception starting filter struts2

转)strut2新手必看(想搞懂struts2必须要看的哦)--struts2-core-2.1.6.jar

2009-06-07 02:12

因为学过struts1.0,最近看企业开发中看重struts2+ext-js技术非常的普遍,研究了一中午,一个简单的小例子都没出来,仔细看了一下错误才知道,原来各种开源框架的支持更新影响的。希望想学struts2的,可以深读这篇文章,吸取教训。

开发环境:(一定要慎重)

我用的是最新的struts-2.1.6

myeclipse 6.5+tomcat6.0(在这一定要是5.5的,并且jdk1.5以上的版本)

最基本的小程序用到jar包,struts2-core.jar,commons-logging.jar,freemarker.jar,ognl.jar,xwork.jar(注意了,struts2-core-2.1.6.jar时要附加上两个包,commons-ileupload.jar 和 commons-io.jar )

还有了在配置web.xml文件时记得不要在用这个过滤器了,<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>,新版本都是过时的了,采取该过滤器,

<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>。

如果在一切搞定之后,还是显示不出来,看看是否是这个错误:

安装实例配置好以后,开始运行,可是出现一下错误:

严重: Exception starting filter struts2 Unable to load configuration. - bean - jar:file:/E:/struts2/struts2/WebRoot/WEB-INF/lib/struts2-core-2.1.6.jar!/struts-default.xml:46:178 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403) at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275) at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3709) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4363) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardHost.start(StandardHost.java:719) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:516) at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:578) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) Caused by: Unable to load bean: type:org.apache.struts2.dispatcher.multipart.MultiPartRequest class:org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest - bean - jar:file:/E:/struts2/struts2/WebRoot/WEB-INF/lib/struts2-core-2.1.6.jar!/struts-default.xml:46:178 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:222) at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101) at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:165) at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55) ... 21 more Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUploadException at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389) at java.lang.Class.getDeclaredConstructors(Class.java:1836) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:212) ... 24 more Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileUploadException at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) ... 28 more 2009-2-16 15:07:42 org.apache.catalina.core.StandardContext start 严重: Error filterStart 2009-2-16 15:07:42 org.apache.catalina.core.StandardContext start 严重: Context [/struts2] startup failed due to previous errors

 

错误中指明struts-default.xml:46:178,struts2-core.jar包中的struts-default文件的46行有问题,于是我打开struts-default.xml,46行为:

 

<bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="struts" class="org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest" scope="default"/>

 

发现要加载org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest。查看这个类的源文件 其中前面有这样几句 :

 

package org.apache.struts2.dispatcher.multipart;

import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.RequestContext; import org.apache.commons.fileupload.disk.DiskFileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload;

import org.apache.struts2.StrutsConstants;

import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory;

public class JakartaMultiPartRequest implements MultiPartRequest {

//下面略 在这个类中必须引入org.apache.commons.fileupload.*; 而错误也许没有加载这个文件上传包所以找不到类 。

于是我就把commons-ileupload.jar 和 commons-io.jar 导入,结果错误解决了。

最后 本人的一点小建议,TOMCAT只是一个开源的web容器技术处理功能还是单调点,建议用jBoss ,他的好处一个功能强大的服务器不仅支持web 还有许多如 ejb 等,最主要的是他的调试错误比较完善,用jboss 4.0 版本运行该程序没有出现异常。

 

你可能感兴趣的:(java,apache,bean,struts,jboss)