日期:2014-05-18  浏览次数:20674 次

struts2 自定义拦截器 不调用
如题,这是配置:
  <constant name="struts.enable.DynamicMethodInvocation" value="true" />
    <constant name="struts.devMode" value="true" />

    <package name="test" namespace="/" extends="struts-default">
     <interceptors>
         <interceptor name="a" class="ysgw/dave/myInterceptor/MyInterceptor"/>
        </interceptors>

        <default-action-ref name="test" />

        <global-results>
            <result name="error">/error.jsp</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception" result="error"/>
        </global-exception-mappings>
        
        
        
        <action name="test">
            <interceptor-ref name="a"/>
            <interceptor-ref name="defaultStack"/>
            <result> /TestInterceptor.jsp</result>
        </action>
        
     </package> 

这是拦截器代码:
package ysgw.dave.myInterceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class MyInterceptor extends AbstractInterceptor{

/**
 * 
 */
private static final long serialVersionUID = 1L;


@Override
public String intercept(ActionInvocation invocation) throws Exception {
long startTime = System.nanoTime();
System.out.println("start time : " + startTime);
String result = invocation.invoke();
long endTime = System.nanoTime();
System.out.println("end time : " + endTime);
System.out.println("time : " + (endTime - startTime));

return result;
}

}
struts interceptor

------解决方案--------------------
ysgw/dave/myInterceptor/MyInterceptor->ysgw.dave.myInterceptor.MyInterceptor