问候struts2升级的新版本2.5

1、jar包的处理

struts2升级到2.5.16版本,大概需要替换更新的架包如下:

struts2-core-2.5.16.jar、struts2-json-plugin-2.5.16.jar、log4j-api-2.10.0.jar、xstream-1.4.10.jar、commons-io-2.5.jar、commons-lang3-3.6.jar

commons-fileupload-1.3.3.jar、freemarker-2.3.26-incubating.jar、javassist-3.20.0-GA.jar、jackson-annotations-2.9.0.jar、jackson-core-2.9.4.jar

jackson-databind-2.9.4.jar、jackson-dataformat-xml-2.1.2.jar、struts2-rest-plugin-2.5.16.jar

删掉xwork-core-2.3.28.1.jar

2、web.xml的处理

把“<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>”修改成“<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>”

3、所有的strut.xml中添加如下:

眉头:修改成

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>

如果action中使用通配符的话,需要在action便签之前添加:这是因为新的版本使用的新的安全机制

<global-allowed-methods>regex:.*</global-allowed-methods>

 

由于新版本的Struts默认不能修改action的访问后缀,不能使用通配的方式调用action里的方法,所以添加(注意下,这个可能不是必要的

注意下放的位置

<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<constant name="struts.enable.SlashesInActionNames" value="true"/>

使得<constant name="struts.action.extension" value="do" />可以生效

<package name="mypackage" namespace="/" extends="struts-default" strict-method-invocation="false"> 注意这里添加了strict-method-invocation="false"(注意下,这个可能不是必要的

 还有一点是个坑呀:

 java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V,让我很是费劲了一番,后来,我就拼命的google和百度,结果还是不行,费了我一个下午和一个早上的时间,最后还是不行,我彻底的服了。最后找到了解决的办法:

出现<init>(Z)V将
将cglib.jar 由2.1版本 改为 2.2
出现<init>(I)V将
将cglib.jar 由2.2版本 改为 2.1

cglib.jar 下载地址    http://www.java2s.com/Code/Jar/c/Downloadcglib220jar.htm   点击下面圈起来的就下载了

如果项目还有有问题的话,接着升级其他的jar包即可

猜你喜欢

转载自www.cnblogs.com/haoxiu1004/p/9283040.html