struts2.3.32升级到struts2.5.26

下载struts2.5.26jar包

官网下载

更新jar

新增或替换

asm-7.3.1.jar
asm-analysis-7.3.1.jar
asm-commons-7.3.1.jar
asm-tree-7.3.1.jar
commons-lang3-3.8.1.jar
commons-io-2.6.jar
commons-fileupload-1.4.jar
javassist-3.20.0-GA.jar
log4j-api-2.12.1.jar
ognl-3.1.28.jar
struts2-core-2.5.26.jar
struts2-json-plugin-2.5.26.jar
struts2-junit-plugin-2.5.26.jar
struts2-spring-plugin-2.5.26.jar
xpp3_min-1.1.4c.jar
xstream-1.4.11.1.jar
xmlpull-1.1.3.1.jar

删除

xwork-core-2.3.32.jar
2.5.X已把xwork-core整合到struts2-core,所以删除

修改web.xml

<filter>
	<filter-name>struts2</filter-name>
	<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

修改weblogic.xml(如果有)

新增session-descriptor

<weblogic-web-app>
	<session-descriptor>
		<cookie-name>JSESSIONID1</cookie-name>
	</session-descriptor>
</weblogic-web-app>

修改struts.xml

2.1–》2.5

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd">

新增配置

  • package标签添加strict-method-invocation="false"和下列标签。
  • global-allowed-methods:放最下面,过滤自定义action的方法,不然不能访问
  • 如果已经配置struts.properties,可不加constant标签
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.action.extension" value="do" />
<package extends="struts-default" strict-method-invocation="false">
	<global-results>
    </global-results>
    <global-allowed-methods>regex:.*</global-allowed-methods>
</package>

修改struts.xml的result-types配置

  • 注释部分为struts2.3.32配置
<?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>
	<package name="struts-default" abstract="true"  strict-method-invocation="false">
		<result-types>
            <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
            <!-- <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult"/> -->
            <result-type name="dispatcher" class="org.apache.struts2.result.ServletDispatcherResult" default="true"/>
            <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult" default="true"/>
            <!-- <result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
            <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
            <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
            <result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
            <result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/> -->
            <result-type name="httpheader" class="org.apache.struts2.result.HttpHeaderResult"/>
            <result-type name="redirect" class="org.apache.struts2.result.ServletRedirectResult"/>
            <result-type name="redirectAction" class="org.apache.struts2.result.ServletActionRedirectResult"/>
            <result-type name="stream" class="org.apache.struts2.result.StreamResult"/>
            <result-type name="velocity" class="org.apache.struts2.result.VelocityResult"/>
            <result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
            <!-- <result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
            <result-type name="postback" class="org.apache.struts2.dispatcher.PostbackResult" /> -->
            <result-type name="plainText" class="org.apache.struts2.result.PlainTextResult" />
            <result-type name="postback" class="org.apache.struts2.result.PostbackResult" />
            <!--自定义result-type-->
        	<result-type name="json" class="org.apache.struts2.json.JSONResult">
				<param name="root">jsonRoot</param>
			</result-type>			
        </result-types>
        <interceptors>
			<interceptor name="i18n" class="org.apache.struts2.interceptor.I18nInterceptor"/>
            <!-- <interceptor name="i18n" class="com.opensymphony.xwork2.interceptor.I18nInterceptor"/> -->
		</interceptors>
		<!-- 其他配置不变,这里略 -->
		<default-class-ref class="com.opensymphony.xwork2.ActionSupport" />
        <global-allowed-methods>regex:.*</global-allowed-methods>
    </package>
</struts>

如果重写了ParametersInterceptor.java类

原方法

protected Map<String, Object> retrieveParameters(ActionContext ac) {
   
    return ac.getParameters();
}

新方法

protected Map<String, String[]> retrieveParameters(ActionContext ac) {
   
   HttpParameters httpParameters = ac.getParameters();
   return httpParameters.toMap();
}

处理上传附件问题(2021.03.30修改)

修改struts.xml的interceptors配置

  • 注释部分为struts2.3.32配置
<?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>
	<package name="<
  • 4
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值