刚接触struts2,今天搭个环境,试用一下,做了个简单的登录+跳转,就出现了二个问题...现在把问题及解决方法记一下:
1.出现错误如下:
Unable to load configuration. - bean - jar:file:/F:/tomcat/webapps/MgMail/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:29:72
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:374)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:418)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
网上查了下,是因为少放了jar包,本来说只放xwork-core-2.1.6.jar,struts2-core-2.1.8.1.jar,ognl-2.7.3.jar,freemarker-2.3.15.jar,commons-logging-1.0.4.jar这4个就可以了,但是其实还要放commons-fileupload-1.2.1.jar.将包放入lib下,错误解决,具体原因未知........
2.出现错误如下
Could not find action or result
There is no Action mapped for namespace / and action name login. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
本来以为是namespace 配置有问题,后来发现,因为我的struts2.xml在放在src下,但是项目没把它output到web-inf\classes下,关掉tomcat,cleanup一下工程.有了,成功.