在执行完Action之后进行拦截没有什么意义啊,因为这种你完全可以在Action里面自己处理。

解决方案 »

  1.   

    这样可以去掉重复代码, 不用每一个ACTION都写拦截器中的代码
      

  2.   

    我一直不明白这一段代码为什么是执行完JSP后, 再去执行拦截器的after方法
    struts2是怎么做到呢?
       1. public abstract class AroundInterceptor extends AbstractInterceptor {  
       2.       
       3.     /* (non-Javadoc) 
       4.      * @see com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com.opensymphony.xwork2.ActionInvocation) 
       5.      */  
       6.     @Override  
       7.     public String intercept(ActionInvocation invocation) throws Exception {  
       8.         String result = null;  
       9.   
      10.         before(invocation);  
      11.         // 调用下一个拦截器,如果拦截器不存在,则执行Action  
      12.         result = invocation.invoke();  
      13.         after(invocation, result);  
      14.   
      15.         return result;  
      16.     }  
      17.       
      18.     public abstract void before(ActionInvocation invocation) throws Exception;  
      19.   
      20.     public abstract void after(ActionInvocation invocation, String resultCode) throws Exception;  
      21.   
      22. }  
      

  3.   

    使用PreResultListener就可以实现了
    相应拦截器的方法中注册监听:invocation.addPreResultListener(new XXListener());正常来讲,before是在之前拦截,after是在调用action之后且执行了result后才拦截如果使用拦截器注解就还会有一个BeforeResult,也就是在调用action之后且没有执行result的时候被拦截
    也就相当于上面的PreResultListener
      

  4.   


    // 添加监听器PreResultListener
            invocation.addPreResultListener(new PreResultListener() {
               
                public void beforeResult(ActionInvocation invocation, String resultCode) {
                    
                    System.out.println(resultCode);
                    
                    // 对返回的代码做你要做的事
                    
                }        });
    大概就是这样~~~
      

  5.   

    有validate 验证一下。然后再执行Action
      

  6.   

    他是想在Action之后在拦截一下~~~~