struts2_大纲05_拦截器

本文详细介绍了Struts框架中拦截器(Interceptor)的工作原理及执行流程,并提供了创建自定义拦截器的具体步骤,包括实现Interceptor接口并重写init、destroy及intercept方法。此外,还展示了如何在struts.xml配置文件中定义和使用拦截器。
1,interceptor原理,执行过程


2,创建一个interceptor,实现interceptor接口


3.重写三个方法: init()
      destroy()
      intercept(ActionInvocation arg0)
4.struts.xml文件中进行配置例如:
<struts>
<package name="struts" extends="struts-default">
<interceptors>
<interceptor name="proInterceptor" class="com.softeem.action.ProIntercept"></interceptor>
<interceptor-stack name="roleIntercept">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="proInterceptor"></interceptor-ref>
</interceptor-stack>
</interceptors>

<action name="loginAction" class="com.softeem.action.LoginAction">
<result type="chain">managerAction</result>
</action>

<action name="managerAction" class="com.softeem.action.ManageAction">
<interceptor-ref name="roleIntercept"></interceptor-ref>
<result>/success.jsp</result>
</action>
</package>
</struts>    



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值