正如在之前所編寫代碼一樣,可以發現,在一個項目裡面至少需要以下幾種攔截器:
驗證攔截,登入攔截,defaultStack攔截,可是如果每一次都這樣分别去寫;
<interceptor-ref name="timer"/>
<interceptor-ref name="mldn"/>
<interceptor-ref name="login"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
如果說要同時編寫多個攔截器引用以上的代碼就明顯感覺第重複了,而且也不友善管理.是以為了友善多個攔截器的管理操作,可以定義一個攔截器棧,在這個攔截器棧中可以引用多個攔截器
範例:定義攔截器棧
<interceptors>
<interceptor-stack name="zwbstack">
<interceptor-ref name="mldn"/>
<interceptor-ref name="login"/>
<interceptor-ref name="timer"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
<interceptor name="mldn" class="cn.mldn.interceptor.MyInterceptor"></interceptor>
<interceptor name="login" class="cn.mldn.interceptor.Logininterceptor"></interceptor>
</interceptors>
<global-results >
<result name="forward.page">forward.jsp</result>
</global-results>
<action name="MessageAction" class="cn.mldn.action.MessageAction">
<interceptor-ref name="zwbstack"></interceptor-ref>
</action>
</package>
這種的操作形式是以後開發之中,使用最多的一種形式的結構.
總結
攔截器是可以由使用者自己來決定執行順序的
是在執行Action之前的一項處理操作!