Structs2的interceptor模拟实现
1、自定义interceptor接口
public interface MyInterceptor { public void interceptor(Invocation invocation); }
2、拦截器1
public class FirstInterceptor implements MyInterceptor { @Override public void interceptor(Invocation invocation) { System.out.println("第一次拦截开始---------"); invocation.invoke(); System.out.println("第一次拦截结束---------"); } }
3、拦截器2
public class SecondInterceptor implements MyInterceptor { @Override public void interceptor(Invocation invocation) { System.out.println("第二次拦截开始---------"); invocation.invoke(); System.out.println("第二次拦截结束---------"); } }
4、Invocation的实现
import java.util.ArrayList; import java.util.List; public class Invocation { List<MyInterceptor> interceptors = new ArrayList<MyInterceptor>(); int index = -1; public Invocation() { this.interceptors.add(new FirstInterceptor()); this.interceptors.add(new SecondInterceptor()); } public void invoke() { index++; if (index < interceptors.size()) { interceptors.get(index).interceptor(this); } else { // 拦截器拦截完毕后执行Action new Action().execute(); } } }
5、模拟Action类
public class Action { public void execute() { System.out.println("Action 执行**********************"); } }
6、客户端Client调用
public class Client { public static void main(String[] args) { new Invocation().invoke(); } }
总结:
Structs2拦截器的实现方式类似于设计模式中的责任链模式,为了能更容易理解拦截器的原理http://787141854-qq-com.iteye.com/admin/blogs/2070819,建议先去学习一下责任链模式。
相关推荐
详细介绍struts2 interceptor
struts2 Interceptor拦截器 http://whitewolf.0fees.net
Struts2拦截器(Interceptor) Struts2拦截器(Interceptor)
NULL 博文链接:https://weizhilizhiwei.iteye.com/blog/1005210
Struts2_interceptor_和_filter区别
STRUTS2:拦截器Interceptor
简单的拦截器例子,适合初学者学习,也是一个备忘录
用注解(annotation)方式配置struts2 (webwork) 中action的拦截器(interceptor)
Struts2拦截器是在访问某个Action或Action的某个方法,字段之前或之后实施拦截,并且Struts2拦截器是可插拔的,拦截器是AOP的一种实现.
struts1 拦截器功能的实现。struts2 中的interceptor很方便。但在struts1中没有这个功能,用这个插件很容易实现。
Struts2.3.6实现自定义拦截器Interceptor http://blog.csdn.net/alanchen520/article/details/34086699
07 Struts 2的基石——拦截器(Interceptor) 08 在Struts 2中实现IoC 09 在Struts 2中实现文件上传 10 在Struts 2中实现CRUD 11 Struts 2中的OGNL 12 Struts 2的新表单标志的使用 13 Struts 2与AJAX
用sevrlet模拟Struts2的简单功能。从拦截请求、解析自定义xml数据文件以及动态生成action的代理去执行目标方法,并实现了简单的日志拦截【interceptor】
很好的struts2入门教程,网上搜集整理的!... ·Struts 2中实现IoC ·Struts 2中实现文件上传 ·Struts 2中的OGNL ·Strus 2的新表单标签的使用 ·Struts 2与AJAX ·Struts2分页 ·完全Struts's Tiles入门
综合使用servlet filter与struts2 interceptor对权限进行验证。
Struts2.x_Interceptor已经打包好了,解压后直接用,
07 Struts 2的基石——拦截器(Interceptor) 08 在Struts 2中实现IoC 09 在Struts 2中实现文件上传 10 在Struts 2中实现CRUD 11 Struts 2中的OGNL 12 trus 2的新表单标志的使用 13 Struts 2与AJAX
Struts 2.0系列(MAX),pdf格式,全...Struts 2的基石——拦截器(Interceptor) 在Struts 2中实现IoC 在Struts 2中实现文件上传 在Struts 2中实现CRUD Struts 2中的OGNL Strus 2的新表单标志的使用 Struts 2与AJAX
struts2 拦截器_教程.zip
Interceptor,学习Struts 2实例,一步步教你如何实现一个示例