继承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的内建拦截器:

 

posted on 2017-03-04 12:43  小学森也要学编程  阅读(152)  评论(0编辑  收藏  举报