struts2.3.33升级到2.5.30
1、struts2.5.30 jar包下载
https://struts.apache.org/download.cgi
2、jar包
- struts2核心包替换
struts2-convention-plugin-2.3.33.jar ->struts2-convention-plugin-2.5.30.jar
struts2-dojo-plugin-2.3.33.jar (删除)
struts2-jasperreports-plugin-2.3.33.jar (删除)
struts2-json-plugin-2.3.33.jar -> struts2-json-plugin-2.5.30.jar
struts2-rest-plugin-2.3.24.1.jar -> struts2-rest-plugin-2.5.30.jar
struts2-spring-plugin-2.3.33.jar -> struts2-spring-plugin-2.5.30.jar
javassist-3.12.0.GA.jar -> javassist-3.18.1-GA.jar
log4j-1.2.17.jar -> log4j-api-2.12.4.jar
ognl-3.0.19.jar-> ognl-3.1.29.jar
xml-apis.jar-> xml-apis-1.0.b2.jar
xwork-core-2.3.33.jar(删除)
cglib-2.2.jar -> cglib-3.1.jar
xstream-1.2.2.jar -> xstream-1.4.17.jar
jackson-annotations-2.10.5.jar、jackson-core-2.10.5.jar、jackson-databind-2.10.5.1.jar(新增)
commons-lang3-3.2.jar->commons-lang3-3.8.1.jar
3、web.xml
<filter-class>
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
</filter-class>
StrutsPrepareAndExecuteFilter类包名变更
<filter-class>
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
</filter-class>
4、struts.xml修改
替换头
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
添加strict-method-invocation="false"和<global-allowed-methods>regex:.*</global-allowed-methods>
<bean name="customJson" class="org.apache.struts2.rest.handler.HtmlHandler" type="org.apache.struts2.rest.handler.ContentTypeHandler"/>
<package name="tdefault" namespace="/" extends="json-default" strict-method-invocation="false">
...
<global-results>
...
<result name="json" type="json">
<param name="noCache">true</param>
<param name="ignoreHierarchy">false</param>
<param name="contentType">text/plain</param>
<param name="excludeNullProperties">true</param>
</result>
</global-results>
<global-allowed-methods>regex:.*</global-allowed-methods>
5、 escape="false"属性替换成escapeHtml="false"
6、maxLength属性无效,直接删除
7、 json解析异常
新增了strut2-rest-plugin-2.5.30.jar后,会导致json解析异常,需要在struts.xml中配置json解析bean,然后在struts.properies中配置struts.rest.handlerOverride.json和struts.rest.content.restrictToGET=false
工程中没有struts.properies文件,在config下新建一个struts.properies
//struts2.xml
<bean name="customJson" class="org.apache.struts2.rest.handler.HtmlHandler" type="org.apache.struts2.rest.handler.ContentTypeHandler"/>
//struts.properies
struts.rest.handlerOverride.json=customJson
struts.rest.content.restrictToGET=false
网友评论