struts2架构中核心对象的探索—— ActionContextClearUp

来源:互联网 发布:大数据 涂子沛 下载 编辑:程序博客网 时间:2024/05/17 07:56

ActionContextClearUp其实是Defer ClearUP.作用就是延长action中属性的生命周期,包括自定义属性,以便在jsp页面中进行访问,让actionContextcleanup过滤器来清除属性,不让action自己清除。
具体看下面的代码,代码很简单

public void doFilter(...){     ...    try{      ...      //继续执行所配置的chain中的Filter      chain.doFilter(request, response);    }finally{      //保证在所有动作执行完之后,调用cleanUp      ...      cleanUp(request);    }  }  protected static void cleanUp(ServletRequest req) {    ...    ActionContext.setContext(null);//清除ActionContext实例    Dispatcher.setInstance(null);//清除Dispatcher实例(Dispatcher主要是完成将url解析成对应的Action)  }  

另外注明一下UtilTimerStack的push和pop是用来计算调用方法所执行的开始和结束时间,用来做性能测试的。用法如下:

String timerKey = "ActionContextCleanUp_doFilter: ";  UtilTimerStack.setActive(true);  UtilTimerStack.push(timerKey);  //调用要测试的方法。  UtilTimerStack.pop(timerKey);
阅读全文
0 0
原创粉丝点击