Struts 2.0 拦截器
来源:互联网 发布:js 定义一个多维数组 编辑:程序博客网 时间:2024/05/01 23:12
Struts 2.0 拦截器
简介
在Struts 2.0 中的拦截器,要实现com.opensymphony.xwork2.interceptor.Interceptor接口,在struts.xml中配置。可以用拦截器来完成调用Action业务逻辑之前的预处理或是之后的善后处理。还可以通过配置多个拦截器来满足action需求。
Interceptor stack是由多个拦截器组成的拦截器组,在拦截器组中可以对每一个拦截器映射。所有进行配置拦截器时,不必对每一个拦截器进行配置,而只需对interceptor stack进行配置即可。在struts 2中默认配置了一个全局interceptor stack,包括Exception Interceptor、Validation Interceptor等。
实例
在这个实例当中,我将配置一个时间拦截器,用来统计每个action的请求时间。
package interceptor;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
public class ActionTimer implements Interceptor{
public String intercept(ActionInvocation next) throws Exception {
long t1 = System.currentTimeMillis();
String s= next.invoke();
long t2 = System.currentTimeMillis();
System.out.println("Action "+next.getAction().getClass().getName()+" took "+(t2-t1)+" millisecs");
return s;
}
public void init() {
}
public void destroy() {
}
}
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="interceptor" extends="struts-default">
<interceptors>
<interceptor name="actiontimer"
class="interceptor.ActionTimer" />
<interceptor-stack name="demostack">
<interceptor-ref name="defaultStack" />
<interceptor-ref name="actiontimer" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="demostack" />
<action name="InterceptorDemo"
class="interceptor.action.InterceptorDemo">
<result>/interceptor/interceptordemo.jsp</result>
</action>
</package>
</struts>
interceptordemo.jsp:
<html>
<head>
</head>
<body>
</body>
</html>
- Struts 2.0 拦截器
- Struts 2.0 拦截器原理解读
- struts拦截器
- struts 拦截器
- Struts 2拦截器
- Struts拦截器
- Struts 2拦截器
- struts拦截器
- Struts之拦截器
- struts拦截器
- Struts 拦截器
- struts拦截器
- struts 2 拦截器
- struts 拦截器
- struts自定义拦截器
- struts 拦截器 interceptor
- struts 拦截器总结
- struts拦截器使用方法
- 解决电脑右键点击后反应缓慢的方法
- ~~给儿子找媳妇
- watch窗口语法规则|vc watch窗口查看指针指向的数组
- 类的设计
- 在Hibernate中配置Proxool连接池
- Struts 2.0 拦截器
- 元件封装
- 光标无法定位到网页输入框
- 软件测试用例
- 注释(@,annotation)在JAVA在用法
- 老人与海读后感
- C#多线程浅谈(存档)
- 新浪选项卡效果
- 30个Oracle语句优化规则详解