Struct2.1-Struct2.5.10版本存在重要的安全漏洞,因此咱们须要升级到2.5.13版本,html
升级方法以下:java
1.须要删除的jar包web
2.须要增长的jar包apache
3.替换structs.xmljson
位置:config/structs.xml安全
修改内容:spa
a. 头部改成(这个是用来指定文件中容许使用那些标签)orm
b. 关键地方 struts2.5 为了提高安全性,添加了 allomethod 标签xml
c.因为新版本的Struts默认不能修改action的访问后缀,不能使用通配的方式调用action里的方法,因此添加htm
使得<constant name="struts.action.extension" value="do" />能够生效
d.
注意这里添加了:strict-method-invocation="false"( action标签method属性开启)
4.替换web.xml
位置:WebContent/WEB-INFO/web.xml
修改内容:
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>修改为“
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>”
缘由:新版本的filter包前面没有ng包
5.在config目录下添加log4j2.xml
缘由:
log4j 2.x版本再也不支持像1.x中的.properties后缀的文件配置方式,2.x版本配置文件后缀名只能为".xml",".json"或者".jsn".因此咱们把以前log4j.properties配置信息迁移到新的log4j2.xml中。
详细配置文件节点解析说明请参考:https://www.cnblogs.com/hafiz/p/6170702.html
,
6.在src\ICT\framework\web.struts2包下替换XssInterceptor.java
缘由:
Apache官方修改了invocation.getInvocationContext().getParameters();接口的实现,原来返回的是一个java.util.Map,如今返回了一个org.apache.struts2.dispatcher.HttpParameters类型的对象
注:页面提交表单的时候不要用struts自带的<s:form>和<s:form>的namespace属性,最好也别用$("#").submit()提交,会出现action不管返回success仍是其它的,页面就是不不变,也不是404和500,页面就是不动。解决办法舍弃用<s:form>,直接用普通的<form></form>表单