读书人

struts2 自定义拦截器 不调用解决思路

发布时间: 2013-03-12 11:19:35 作者: rapoo

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

读书人网 >J2EE开发

热点推荐