(二十二)拦截器栈

        正如在之前所编写代码一样,可以发现,在一个项目里面至少需要以下几种拦截器:

验证拦截,登录拦截,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之前的一项处理操作!


猜你喜欢

转载自blog.csdn.net/qq1019648709/article/details/80608530