首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

拦截器学习指点

2012-11-13 
拦截器学习指导struts2以可插拔式来管理action需要完成的通用操作。系统为拦截器指定参数的两种形式:(1)定

拦截器学习指导
struts2以可插拔式来管理action需要完成的通用操作。
系统为拦截器指定参数的两种形式:
(1)定义拦截器时指定参数值(<intercepter ...>)
(2)使用拦截器时指定参数值(<intercepter-ref ...>)
配置默认拦截器
<default-interceptor-ref name="defaultStack"/>做为包的子元素
在有时,如权限,日志等都要用到自定义拦截器。
自定义拦截器需要实现com.opensymphony.xwork2.interceptor.Interceptor

public class myIterceptorListener implements PreResultListener{public void beforeResult(ActionInvocation invocation, String resultCode) {System.out.println("逻辑视图返回  "+resultCode);}}..public String intercept(ActionInvocation invocation) throws Exception {invocation.addPreResultListener(new myIterceptorListener());//注册拦截器监听器converAction co=(converAction)invocation.getAction();System.out.println(name+"拦截器开始时间:"+new Date());long start=System.currentTimeMillis();//执行该拦截器的下一个拦截器,或者直接ACTION的execute方法String result=invocation.invoke();System.out.println(name+"拦截器的动作---"+"执行完Action的时间为"+new Date());long end=System.currentTimeMillis();System.out.println(name+"拦截器执行完Action所用时间"+(end-start)+"毫秒");return result;}

热点排行