定义一个拦截器: 第一步: 1.创建一个继承自AbstractInterceptor/Interceptor的类; 2.实现intercept方法(后者需要实现initial()和destroy()方法)。 第二步: 1.在struts.xml文件中对拦截器进行注册;
<interceptors>
<interceptor name="timeinterceptor" class="com.imooc.interceptor.TimerInterceptor"></interceptor>
</interceptors>2.在相应的Action中进行引用。<interceptor-ref name="timeinterceptor"></interceptor-ref>invocation.invoke()表示调用ActionInvocation里的下一个拦截器,如果已经是最后一个,则表示要执行目标的Action,会返回一个字符串,即结果视图。