美文网首页
struts2拦截器的实现

struts2拦截器的实现

作者: 法式大面包 | 来源:发表于2017-04-25 20:25 被阅读0次
    package org.mobiletrain.interceptor;
    
    import com.opensymphony.xwork2.ActionInvocation;
    import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
    
    /**
     *  struts2拦截器继承AbstractInterceptor类
     * @author czy
     *
     */
    public class PerfInterceptor extends AbstractInterceptor {
    
    
     /* 重写intercept方法*/
    @Override
    public String intercept(ActionInvocation invocation) 
            throws Exception {
        long start = System.currentTimeMillis();
        //在执行原方法的前后进行时间计算
        String result = invocation.invoke();
        long end = System.currentTimeMillis();
        String name = invocation.getInvocationContext().getName();
        System.out.println(name + "总耗时为: " + (end - start) + "ms");
        return result;
        }
      }

    相关文章

      网友评论

          本文标题:struts2拦截器的实现

          本文链接:https://www.haomeiwen.com/subject/bbhbzttx.html