struts2系列学习笔记(11)---------------拦截器
2011-01-21 11:30
459 查看
拦截器本质上就是过滤器,是基于AOP思想的产物.在Struts2中,拦截器的作用十分重要!因为框架中大部分的核心功能都是通过拦截器实现的.这样的方式对于系统解耦十分重要.(但是对它的性能也十分担心.....)
1.拦截器的编写:
1)实现com.opensymphony.xwork2.interceptor.Interceptor接口
该接口定义得方法: void init()
void destroy()
String intercept(ActionInvocation invocation)throws Exception
2)继承抽象类com.opensymphony.xwork2.interceptor.AbstractInterceptor
该抽象类是接口的子类,该类对init和destroy方法做了空实现
3)struts2提供的基类拦截器:com.opensymphony.xwork2.interceptor.MethodFilterInteceptor
该类可以针对特定方法进行拦截,反过来也可以排除特定方法
2. 拦截器的定义
1)<interceptor name="拦截器名" class=“拦截器实现类"/>
或
<interceptor name="拦截器名" class=“拦截器实现类">
<param name="参数名">参数值</param> 注:指定参数
</interceptor>
2)
<interceptor-stack name="拦截器名">
<interceptor-ref name="拦截器一"/>
<interceptor-ref name="拦截器二"/> 注:可以引用其它拦截器栈
.....
</interceptor-stack>
3)默认拦截器:每个包只能指定一个默认拦截器,该包中未指定拦截器的Action,默认拦截器将起作用
<default-interceptor-ref name="拦截器或者拦截器栈名"/>
1.拦截器的编写:
1)实现com.opensymphony.xwork2.interceptor.Interceptor接口
该接口定义得方法: void init()
void destroy()
String intercept(ActionInvocation invocation)throws Exception
2)继承抽象类com.opensymphony.xwork2.interceptor.AbstractInterceptor
该抽象类是接口的子类,该类对init和destroy方法做了空实现
3)struts2提供的基类拦截器:com.opensymphony.xwork2.interceptor.MethodFilterInteceptor
该类可以针对特定方法进行拦截,反过来也可以排除特定方法
2. 拦截器的定义
1)<interceptor name="拦截器名" class=“拦截器实现类"/>
或
<interceptor name="拦截器名" class=“拦截器实现类">
<param name="参数名">参数值</param> 注:指定参数
</interceptor>
2)
<interceptor-stack name="拦截器名">
<interceptor-ref name="拦截器一"/>
<interceptor-ref name="拦截器二"/> 注:可以引用其它拦截器栈
.....
</interceptor-stack>
3)默认拦截器:每个包只能指定一个默认拦截器,该包中未指定拦截器的Action,默认拦截器将起作用
<default-interceptor-ref name="拦截器或者拦截器栈名"/>
相关文章推荐
- Struts2-学习笔记系列(11)-使用StrutsTypeConverter
- Struts2-学习笔记系列(14)-拦截器
- struts2学习笔记之拦截器(Interceptor)
- struts2系列学习笔记(6)---------------Action的结果处理
- Struts2-学习笔记系列(6)-动态调用action
- Struts2-学习笔记系列(15)-ajax支持和JSON
- [原创]java WEB学习笔记65:Struts2 学习之路--Struts的CRUD操作( 查看 / 删除/ 添加) ModelDriven拦截器 paramter 拦截器
- Struts2学习笔记04 之 拦截器
- Struts2学习笔记12:Struts2的拦截器【续】
- struts2系列学习笔记(4)---------------Action的多样化配置之二
- Struts2学习笔记之自定义拦截器
- Struts2-学习笔记系列(7)-PreResultListener
- 【Struts2学习笔记(10)】自定义拦截器管理权限访问
- struts2系列学习笔记(7)---------------其它形式的结果处理
- Struts2-学习笔记系列(8)-异常处理
- Struts2学习笔记(5)--拦截器
- struts2系列学习笔记(8)---------------类型转换
- Struts2 学习笔记18 拦截器原理分析
- struts2 拦截器学习笔记01
- 黑马程序员---struts2学习笔记之六(自定义拦截器)