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配置


<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.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.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.result.PlainTextResult" />
            <result-type name="postback" class="org.apache.struts2.result.PostbackResult" />
            
        	<result-type name="json" class="org.apache.struts2.json.JSONResult">
				<param name="root">jsonRootparam>
			result-type>			
        result-types>
        <interceptors>
			<interceptor name="i18n" class="org.apache.struts2.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();
}

你可能感兴趣的:(struts2)