struts2升級到Struts 2.3.15.1的步驟


struts2升級到Struts 2.3.15.1的步驟

 最近struts安全問題影響很大啊,iteye上面也有新聞:Apache Struts團隊6月底發布了Struts 2.3.15版本,由於該版本被發現存在重要的安全漏洞,因此該團隊今天發布了Struts 2.3.15.1安全更新版本。 

新聞地址:http://www.iteye.com/news/28053

 

       因此我升級了下當前項目的struts版本,原來是2.2.3,現在升級到2.3.15.1

 

      首先下載jar包:http://struts.apache.org/download.cgi#struts23151

Essential Dependencies Only:

struts-2.3.15.1-lib.zip (19MB) [PGP] [MD5]

 

從下載的jar包拷貝核心包:

antlr-2.7.2

aopalliance-1.0

asm-3.3

asm-commons-3.3

asm-tree-3.3

builder-0.6.2

classworlds-1.1

commons-beanutils-1.8.0

commons-collections-3.1

commons-chain-1.2

commons-digester-2.0

commons-fileupload-1.3

commons-io-2.0.1

commons-lang3-3.1

commons-lang-2.4

commons-logging-1.1.3

commons-logging-api-1.1

commons-validator-1.3.1

freemarker-2.3.19

ognl-3.0.6

struts2-convention-plugin-2.3.15.1

struts2-core-2.3.15.1

struts2-dojo-plugin-2.3.15.1

struts2-jfreechart-plugin-2.3.15.1

struts2-json-plugin-2.3.15.1

struts2-junit-plugin-2.3.15.1

struts2-spring-plugin-2.3.15.1

xwork-core-2.3.15.1

 

到此先備份原來的所有jar,以防萬一……

刪除項目WEB-INF/lib下:

asm-3.1

struts2-spring-plugin-2.2.3

struts2-junit-plugin-2.2.3

struts2-json-plugin-2.2.3

struts2-jfreechart-plugin-2.2.3

struts2-dojo-plugin-2.2.3

struts2-core-2.2.3

ognl-2.7.3

freemarker-2.3.15

commons-collections-3.1

commons-io-1.3.2

commons-fileupload-1.2.1

commons-beanutils-1.7.0

commons-validator-1.3.1

xwork-core-2.2.3

 

最安全的做法:

        以核心jar為准,如果在原lib里有同名但不同版本的jar就replace,沒有就直接copy,替換方式遵循“誰新替換誰”的原則。

      (小插曲:我拷貝了核心jar里的antlr-2.7.2,但是我原來的項目里有antlr-2.7.6,我沒注意,結果報java.lang.NoSuchMethodError: antlr.collections.AST.getLine()的錯誤,刪除antlr-2.7.2即可)

         對於struts2開頭的jar,只要原來有的,都在核心jar里找到替換的版本,沒有同名的就不換。

 

請注意:原lib里的commons-collections、commons-lang、commons-logging要保留。

 

 

刷新后(請確保更換lib之前項目是運行無誤的…蠢話),重新配置tomcat並運行……

 

如果遇到一些NoSuchMethod或者NotClassFound等等的提示,檢查一下是不是誤刪了原來的某個jar;

 

如果看到如此提示:

 

*********************************************************************** 
*                               WARNING!!!                            * 
*                                                                     * 
* >>> FilterDispatcher <<< is deprecated! Please use the new filters! * 
*                                                                     * 
*           This can be a source of unpredictable problems!           * 
*                                                                     * 
*              Please refer to the docs for more details!             * 
*            http://struts.apache.org/2.x/docs/webxml.html            * 
*                                                                     * 
***********************************************************************

 

在web.xml里把FilterDispatcher 替換成StrutsPrepareAndExecuteFilter(org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter)

 

 

如果看到如此提示:

 

*********************************************************************** 
*                               WARNING!!!                            * 
*                                                                     * 
* >>> ActionContextCleanUp<<< is deprecated! Please use the new filters! * 

*                                                                     * 
*           This can be a source of unpredictable problems!           * 
*                                                                     * 
*              Please refer to the docs for more details!             * 
*            http://struts.apache.org/2.x/docs/webxml.html            * 
*                                                                     * 
***********************************************************************

 

同樣是在web.xml里把ActionContextCleanUp替換成StrutsPrepareAndExecuteFilter(org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter)

 

       若原來就配置有StrutsPrepareAndExecuteFilter,則把ActionContextCleanUp去掉。

       

       比如我這里修改后的樣子:

   

Xml代碼   收藏代碼
  1. <span style="font-size: 16px;"><!-- STRUTS配置 -->  
  2.      <!-- <filter>  升級到2.3.15.1后要去掉  
  3.         <filter-name>struts2-cleanup</filter-name>  
  4.         <filter-class>  
  5.             org.apache.struts2.dispatcher.ActionContextCleanUp  
  6.         </filter-class>  
  7.     </filter>  
  8.     <filter-mapping>  
  9.         <filter-name>struts2-cleanup</filter-name>  
  10.         <url-pattern>/*</url-pattern>  
  11.     </filter-mapping>  -->  
  12.       
  13.        
  14.     <filter>  
  15.         <filter-name>struts2</filter-name>  
  16.         <filter-class>  
  17.         org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  
  18.         </filter-class>  
  19.     </filter>  
  20.     <filter-mapping>  
  21.         <filter-name>struts2</filter-name>  
  22.         <url-pattern>*.action</url-pattern>  
  23.         <dispatcher>REQUEST</dispatcher>  
  24.         <dispatcher>FORWARD</dispatcher>  
  25.     </filter-mapping>  
  26. </span>  

 

 

關於升級后的web.xml配置請參考:

http://struts.apache.org/development/2.x/docs/webxml.html

原地址:http://weilikk.iteye.com/blog/1931527


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM