struts2学习笔记(5)拦截器

继承AbstractInterceptor类,在类中完成拦截器的功能,只需实现intercept方法即可,提供了init()和destroy()的空实现

示例:显示执行action所用的时间

①在src中建包com.lzhc.interceptor,在包中建TimerInterceptor.java,使其继承AbstractInterceptor类

②在struts.xml中进行配置

在package内注册拦截器,代码如下:

<interceptors>

  <interceptor name="mytimer" class="com.lzhc.interceptor.TimerInterceptor"></interceptor>

</interceptors>

在需要用到拦截器的action中添加

<interceptor-ref name="mytimer"></interceptor-ref>

struts2的内建拦截器:

原文地址:https://www.cnblogs.com/lzhc/p/6501037.html