struts2.3 升级 struts2.5

1、版本

<struts2.version>2.5.10.1</struts2.version>
<spring.version>4.1.6.RELEASE</spring.version>

2、相关jar说明

Maven: org.apache.struts:struts2-convention-plugin:2.5.10.1
Maven: org.apache.struts:struts2-core:2.5.10.1
Maven: org.apache.struts:struts2-json-plugin:2.5.10.1
Maven: org.apache.struts:struts2-spring-plugin:2.5.10.1

Maven: org.springframework:spring-aop:4.1.6.RELEASE
Maven: org.springframework:spring-beans:4.1.6.RELEASE
Maven: org.springframework:spring-context:4.1.6.RELEASE
Maven: org.springframework:spring-context-support:4.1.6.RELEASE
Maven: org.springframework:spring-core:4.1.6.RELEASE
Maven: org.springframework:spring-expression:4.1.6.RELEASE
Maven: org.springframework:spring-jdbc:4.1.6.RELEASE
Maven: org.springframework:spring-jms:4.1.6.RELEASE
Maven: org.springframework:spring-messaging:4.1.6.RELEASE
Maven: org.springframework:spring-orm:4.1.6.RELEASE
Maven: org.springframework:spring-oxm:4.1.6.RELEASE
Maven: org.springframework:spring-test:4.1.6.RELEASE
Maven: org.springframework:spring-tx:4.1.6.RELEASE
Maven: org.springframework:spring-web:4.1.6.RELEASE
Maven: org.springframework:spring-webmvc:4.1.6.RELEASE

注意:需要删除

Maven: org.apache.struts.xwork:xwork-core:2.3.32

strut2.5中,xwork-core是与struts2-core合并的 pom文件中,需要忽略这个jar文件

<exclusions>
    <exclusion>
        <groupId>org.apache.struts.xwork</groupId>
        <artifactId>xwork-core</artifactId>
    </exclusion>
</exclusions>

3、相关代码说明

替换struts-tags.tld文件,最新的在strut2-core.jar META-INF中
替换security.tld文件,最新的在spring-security-taglibs-3.2.4.RELEASE.jar META-INF中

web.xml

<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
替换为
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareFilter</filter-class>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsExecuteFilter</filter-class>
原:这用到xwork-core 的jar,所有方法是返回的MAP
Map<String, Object> parameters = invocation.getInvocationContext().getParameters();

现在:用到的是stuts2-core-2.5.10.1.jar

拦截器中:invocation.getInvocationContext().getParameters()
返回的是
HttpParameters parameters = invocation.getInvocationContext().getParameters();

HttpParameters 类型为 Map

@Override
public Parameter put(String key, Parameter value) {
    throw new IllegalAccessError("HttpParameters are immutable, you cannot put value directly!");
}

HttpParameters  不支持put,会直接抛出异常,用到的同学请注意了。。。

严重:struts2.5中,不在默认使用通配符进行访问action中的方法(http://url!方法名称.html), 不默认支持”!”

如果需要使用

> 第一种

<struts>
<package name="default" namespace="/" extends="struts-default">
   <global-allowed-methods>regex:.*</global-allowed-methods>
    <action name="helloworld" class="com.imooc.action.HelloWorldAction">
        <result>/result.jsp</result>
        <result name="add">/add.jsp</result>
        <result name="update">/update.jsp</result>
    </action>
</package>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
</struts>

增加:

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

action配置上面:

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

> 第二种
@AllowedMethods(value = {"方法名称1","方法名称2"})
Action中增加注解,注册Action中的方法
示例:

@AllowedMethods(value = {"save","update"})

Paste_Image.png

结语

如果在启动的时候发现有注解的错误~~
很有可能是引用的其它项目的jar文件,中使用struts2-core低版本进行了编译打包~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值