您的位置:首页 > 编程语言 > Java开发

struts2——自定义拦截器!!!

2010-09-28 16:35 357 查看
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class MyInterceptor implements Interceptor {
public String intercept(ActionInvocation invocation) throws Exception {
long start = System.currentTimeMillis();
String str = invocation.invoke();
long end = System.currentTimeMillis();
System.out.println("action time:" + (end - start));
return str;
}

public void destroy() {
}

public void init() {
}
}


<struts>
<package name="test" namespace="/" extends="struts-default">
<interceptors>
<interceptor name="myinterceptor" class="test.MyInterceptor"/>
</interceptors>
<action name="test" class="test.Test">
<result name="success">/hello.jsp</result>
<interceptor-ref name="myinterceptor"/>
<interceptor-ref name="defaultStack"/>
</action>
</package>
</struts>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: