如题,这是配置:
<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;
}
}strutsinterceptor
<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;
}
}strutsinterceptor
<package name="default" extends="struts-default">
<interceptors>
<interceptor name="timer" class=".."/>
<interceptor name="logger" class=".."/>
</interceptors> <action name="login"
class="tutorial.Login">
<interceptor-ref name="timer"/>
<interceptor-ref name="logger"/>
<result name="input">login.jsp</result>
<result name="success"
type="redirectAction">/secure/home</result>
</action>
</package>