自定义拦截器

自定义拦截器,class类要继承AbstractInterceptor,Struts2中的拦截器都是继承它,实现intercept方法:

package com.interceptor;
 
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
 
public class MyInterceptor extends AbstractInterceptor{
 
    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        System.out.println("before");
        String result = invocation.invoke();
        System.out.println("after");
        return result;
    }
 
 
}

Struts.xml中的配置

    
         
    


在action中调用时应先用自定义的,再用默认的
    
    



你可能感兴趣的:(java)