SiteMesh和Struts2,Filter的配置顺序

      Sitemesh和Struts2结合时,要特别注意它们各自Filter的顺序,否则会导致双方都不能正常工作。而又由于Struts2在2.1.3之前使用的是FilterDispatcher,2.1.3之后推荐使用StrutsPrepareFilter和StrutsExecuteFilter替代FilterDispatcher,因此,配置上又会有所不同。
      2.1.3之前的版本,sitemesh的filter要介于StrutsPrepareFilter和FilterDispatcher之间,配置如下:

[xhtml]  view plain copy
  1. <filter>  
  2.        <filter-name>struts-cleanupfilter-name>  
  3.        <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUpfilter-class>  
  4.    filter>    
  5.    <filter-mapping>  
  6.        <filter-name>struts-cleanupfilter-name>  
  7.        <url-pattern>/*url-pattern>  
  8.    filter-mapping>  
  9.      
  10.    <filter>  
  11.        <filter-name>sitemeshfilter-name>  
  12.        <filter-class>com.opensymphony.module.sitemesh.filter.PageFilterfilter-class>  
  13.    filter>    
  14.    <filter-mapping>  
  15.        <filter-name>sitemeshfilter-name>  
  16.        <url-pattern>/*url-pattern>  
  17.    filter-mapping>  
  18.      
  19.    <filter>  
  20.        <filter-name>strutsfilter-name>  
  21.        <filter-class>org.apache.struts2.dispatcher.FilterDispatcherfilter-class>  
  22.    filter>    
  23.    <filter-mapping>  
  24.        <filter-name>strutsfilter-name>  
  25.        <url-pattern>/*url-pattern>  
  26.    filter-mapping>  

       2.1.3之后的版本,sitemesh的filter要介于StrutsPrepareFilter和StrutsExecuteFilter之间,配置如下:

[xhtml]  view plain copy
  1. <filter>  
  2.        <filter-name>struts-cleanupfilter-name>  
  3.        <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUpfilter-class>  
  4.    filter>     
  5. <filter-mapping>  
  6.        <filter-name>struts-cleanupfilter-name>  
  7.        <url-pattern>/*url-pattern>  
  8.    filter-mapping>  
  9.    <filter>  
  10.        <filter-name>struts-preparefilter-name>  
  11.        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilterfilter-class>  
  12.    filter>  
  13. <filter-mapping>  
  14.        <filter-name>struts-preparefilter-name>  
  15.        <url-pattern>/*url-pattern>  
  16.    filter-mapping>  
  17. <filter>  
  18.        <filter-name>sitemeshfilter-name>  
  19.        <filter-class>com.opensymphony.module.sitemesh.filter.PageFilterfilter-class>  
  20.    filter>  
  21. <filter-mapping>  
  22.        <filter-name>sitemeshfilter-name>  
  23.        <url-pattern>/*url-pattern>  
  24.    filter-mapping>  
  25.   
  26.    <filter>  
  27.        <filter-name>struts-executefilter-name>  
  28.        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilterfilter-class>  
  29.    filter>  
  30.    <filter-mapping>  
  31.        <filter-name>struts-executefilter-name>  
  32.        <url-pattern>/*url-pattern>  
  33.    filter-mapping>    

转自:http://blog.csdn.net/bluishglc/article/details/5969769

你可能感兴趣的:(Servlet/JSP,Struts/Spring)