struts2中關於攔截器Interceptor中的excludeMethods和includeMethods的理解

通過對struts2的學習,對於interceptor中的excludeMethods與includeMethods的理解:
針對MethodFilterInterceptor:
excludeMethods表示排除指定的方法,即不對標記爲excludeMethods的方法進行攔截,【攔截是說在Action的基礎上執行攔截器裏面的邏輯】
includeMethods表示包含指定的方法,即對標記爲includeMethods的方法進行攔截,      【不攔截是說在Action的基礎上不執行攔截器裏面的邏輯代碼】
 
在struts.xml中關於excludeMethods和includeMethods有兩種實現方式,一種相當於全局,另一種相當於局部,即<interceptors>
          <interceptor name="method"class="com.yxl.interceptor.MethodInterceptor">
               <paramname="includeMethods">method1,method2</param>
          </interceptor>
       </interceptors>爲全局
而 <interceptor-refname="method">
               <paramname="excludeMethods">method1,method2</param>
     </interceptor-ref> 
爲局部,若全局中的param定義爲excludeMethods同樣局部中的param也定義爲excludeMethods,則局部中的param生效,全局中的param無效,即被局部中的param覆蓋,同樣,若全局中的param定義爲includeMethods同樣局部中的param也定義爲includeMethods,則局部中的param生效,全局中的param無效,即被局部中的param覆蓋。
當全局中的param與局部中的param不相同的時,即當全局中param爲excludeMethods而局部中的param爲includeMethods和全局中的param爲includeMethods而局部中param爲excludeMethods,則標誌爲includeMethods生效,即若是全局中的param定義爲includeMethods,則全局屏蔽局部,以全局爲準,反之,以局部爲準。


尤其值得注意的是,自定義的攔截器類一定要繼承MethodFilterInterceptor
struts2MethodFilterInterceptor類,該類是AbstractInerceptor的子類,可以實現對Action方法的攔截.實現MethodFilterInterceptor才能使用方法攔截
    MethodFilterInterceptor中有兩個方法
   setExcludeMethods:排除需要過濾的方法
    setIncludeMethods:設置需要過濾的方法
    如果一個方法同時在excludeMethods和includeMethods中出現,則會被攔截

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章