Struts2拦截器

一、拦截器的工作原理

拦截器的实现非常类似过滤器,它的工作过程是一个递归的过程。流程如下

           request  -->interceptor 1 ----> interceptor 2 ---->Action--->result---->interceptor2----->interceptor1--->response;

二、自定义拦截器

实现自定义拦截器有两种方法,一种是实现Interceptor接口,另一种是继承AbstractInterceptor类

这里具体讲解继承AbstractInterceptor类

1、定义一个类,继承AbstractInterceptor类。

2、实现该类的 String intercept(ActionInvocation ai) throws Exception方法。

ActionInvocation的作用,获取Action的执行状态,返回result字符串作为逻辑视图。

//执行下一个拦截器,或者执行最终Action,获取返回视图。通过执行String result=ai.invoke()实现

               3、struts.xml中进行interceptor的配置

<interceptors>

<interceptor  name=""   class="">

   Action 使用拦截器

<action>

<interceptor-ref  name="拦截器名"/>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值