都不会配struts2了。。囧。。
刚刚在soso上看到有人问,于是我也去配个struts2,结果发现步骤忘光光。。
首先是导入包、然后配置xml、在src下新建struts.xml文件,之后就自己搞了。。
咦,对方用的是org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter,这是啥米东东?包里没有啊。
百度一下,没找到 - -!
于是怀疑对方打错的俺去google,发现:
org.apache.struts2.dispatcher.FilterDispatcher 在 2.1.6 中已经过时,请用org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter替代。
囧啊啊啊 我的jar包还是2.0的。。于是去官方下了个2.1.8的。。继续试之。。
项目重新部署后,提示:
Unable to load configuration. - bean - jar:file:/F:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/TestAction/WEB-INF/lib/struts2-core-2.1.8.jar!/struts-default.xml:29:72
最后发现是之前的2.0 jar包没有删除,我用的redepoy,可能不会删除原来的?于是remove之后重新add,该错误解决,接下来是:
2009-10-24 13:12:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger fatal
严重: ********** FATAL ERROR STARTING UP STRUTS-SPRING INTEGRATION **********
Looks like the Spring listener was not configured for your web app!
Nothing will work until WebApplicationContextUtils returns a valid ApplicationContext.
You might need to add the following to web.xml:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
估计是加了一些没用的jar包,2.0的时候我只加了5个包,这次也加5个好了:commons-logging、freemaker、struts-core、ognl、xwork,
再次remove+add,那个错误又来了,似曾相识:
Unable to load configuration. - bean - jar:file:/F:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/TestAction/WEB-INF/lib/struts2-core-2.1.8.jar!/struts-default.xml:47:178
代码变成47:178,下面还有原因说明:
Caused by: Unable to load configuration. - bean - jar:file:/F:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/TestAction/WEB-INF/lib/struts2-core-2.1.8.jar!/struts-default.xml:47:178
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)
... 25 more
Caused by: Unable to load bean: type:org.apache.struts2.dispatcher.multipart.MultiPartRequest class:org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest - bean - jar:file:/F:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/TestAction/WEB-INF/lib/struts2-core-2.1.8.jar!/struts-default.xml:47:178
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:221)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:169)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
... 27 more
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/RequestContext
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getDeclaredConstructors(Unknown Source)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:211)
... 30 more
好吧,再加上commons-fileUpload和commons-io,终于可以运行了。。
话说,我才知道原来action里面不配class,就默认返回SUCCESS。。。可以直接在result里面写内容,形如:
-
<action name="hello">
-
<result>/Hello.jsp</result>
-
</action>
这样直接输hello.action是可以跳到Hello.jsp的。。