关于Struts 2的正确配置

前些天刚好开始Struts的学习,但是在配置Struts 2的时候就遇到了很大的障碍,我使用的Struts 2版本是2.2.1(即Struts 2.2.1),我参考了《精通J2EE(第二版)里的有关Struts 2的配置内容,该书使用的是Struts 2.0.9)。我首先从Struts 2.2.1lib文件下复制了“freemarker-2.3.16.jarognl-3.0.jarstruts2-core-2.2.1.jarxwork-core-2.2.1.jar”,然后粘贴在了项目的lib文件下,也可以通过“Add External JARs”的形式导入,但是如上所作后,在启动Tomcat时出现了如下的错误:

警告: Could not create JarEntryRevision for [jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar]

...

2010-9-24 11:16:02 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info

信息: Parsing configuration file [struts-default.xml]

2010-9-24 11:16:02 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error

严重: Dispatcher initialization failed

Unable to load configuration. - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178

<wbr><wbr><wbr></wbr></wbr></wbr>...

Caused by: Unable to load bean: type:org.apache.struts2.dispatcher.multipart.MultiPartRequest class:org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178

<wbr><wbr><wbr></wbr></wbr></wbr>...

Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/RequestContext

<wbr><wbr><wbr></wbr></wbr></wbr>...

2010-9-24 11:16:02 org.apache.catalina.core.StandardContext filterStart

严重: Exception starting filter struts2

Unable to load configuration. - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178

<wbr><wbr><wbr></wbr></wbr></wbr>...

Caused by: Unable to load configuration. - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178

<wbr><wbr><wbr></wbr></wbr></wbr>...<wbr></wbr>

Caused by: Unable to load bean: type:org.apache.struts2.dispatcher.multipart.MultiPartRequest class:org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178

<wbr><wbr><wbr></wbr></wbr></wbr>...<wbr></wbr>

Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/RequestContext

<wbr><wbr><wbr></wbr></wbr></wbr>...

Caused by:java.lang.ClassNotFoundException: org.apache.commons.fileupload.RequestContext

<wbr><wbr><wbr></wbr></wbr></wbr>...

2010-9-24 11:16:02 org.apache.catalina.core.StandardContext start

严重: Error filterStart

2010-9-24 11:16:02 org.apache.catalina.core.StandardContext start

严重: Context [/Struts2] startup failed due to previous errors

<wbr></wbr>

这些错误很让我摸不着头脑,经多方查阅资料后,在Struts 2.2.x中应该导入如下7JAR文件

1)<wbr><wbr></wbr></wbr>commons-fileupload-1.2.1.jar

2)<wbr><wbr></wbr></wbr>commons-io-1.3.2.jar

3)<wbr><wbr></wbr></wbr>freemarker-2.3.16.jar

4)<wbr><wbr></wbr></wbr>javassist-3.7.ga.jar

5)<wbr><wbr></wbr></wbr>ognl-3.0.jar

6)<wbr><wbr></wbr></wbr>struts2-core-2.2.1.jar

7)<wbr><wbr></wbr></wbr>xwork-core-2.2.1.jar

8) commons-lang-2.5.jar

  1. asm-x.x.jar
  2. asm-commons-x.x.jar
  3. asm-tree-x.x.jar
  4. commons-fileupload-X.X.X.jar
  5. commons-io-X.X.X.jar
  6. commons-lang-X.X.jar
  7. freemarker-X.X.X.jar
  8. javassist-X.X.X.jar
  9. ognl-X.X.X.jar
  10. struts2-core-X.X.X.X.jar
  11. xwork-core-X.X.X.jar

<wbr></wbr>

其实,这里还有一个小窍门,我们可以将Struts 2.2.x根目录下的apps文件夹下的struts2-blank-2.2.1.war文件进行解压,然后找到WEB-INF下的lib目录,我们可以发现里面列出了7JAR文件,刚好这7个就是我们配置Struts 2.2.x需要导入的JARs文件:


现在服务器应该就可以正常启动了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值