<p>
struts2.3.15升级到2.5.13
1 、下载 jar 包 struts2.5.13 所有的 jar 包从官网下载的 https://struts.apache.org/index.html 最新的 jar包https://struts.apache.org/download.cgi#struts2513[struts-2.5.13-all-zip[PGP][MD5]]
2 、替换项目中所有 struts 开头的 jar 包(一般替换所有版本较低的包,高版本一般不替换),删除 xwork-core-2.3.15.1.jar (在 struts2.5.13 版本中,这个包已经被整合,避免冲突删除旧包)
3 、修改 web.xml
2.5.13 版本中, StrutsPrepareAndExecuteFilter 的位置变动<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
修改成
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
4 、 struts2 配置修改
Struts.xml 头部修改
头部信息中 struts 的版本修改为 2.5<?xml version="1.0" encoding=""
<?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">
可能出现的报错:
这是因为 struts2.5 为了提升安全性,添加了 allomethod 属性设置。org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException:
org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException:
.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
解决方法是在配置文件中添加:
或者在配置文件中添加:<package name="exam" extends="json-default">
<global-allowed-methods>regex:.*</global-allowed-methods>
<action name="user" class="userAction">
...
</action>
</package>
目前两种方法都测试有效。<constantname="struts.enable.DynamicMethodInvocation"value="true"></constant>
5 、 struts2 页面修改
页面报错:、Struts has detected an unhandled exception:
Messages:
/tagDef/export_record_now.jsp (line: 41, column: 4) Attribute id invalid for tag iterator according to
TLD
File: org/apache/jasper/compiler/DefaultErrorHandler.java
页面中:jstl标签中的变量id要修改为var
</p>