struts2自定义拦截器及其配置(备份)
2010-05-21 10:11
597 查看
代码:
package com.web.action;
import java.util.Date;
import java.util.Map;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
public class HistoryLogStack implements Interceptor {
/**
*
*/
private static final long serialVersionUID = -1385902554116735266L;
public void destroy() {
System.out.println("日志拦截器销毁...");
}
public void init() {
System.out.println("日志拦截器初始化...");
}
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("日志拦截器已经开始启动..");
String result = invocation.invoke();
String actionName= invocation.getAction().getClass().toString();
String method = invocation.getProxy().getMethod();
final Map <String,Object> parameters = invocation.getInvocationContext().getParameters();
System.out.println("Action: " + actionName + ", Method: " + method);
System.out.println("拦截的参数为:");
for (Map.Entry<String, Object> map : parameters.entrySet()) {
System.out.println(map.getKey() + "--" + map.getValue());
}
if(method != null && method.startsWith("save")){
System.out.println("Execute save method..." + new Date());
}
return result;
}
}
配置:
<interceptors>
<interceptor name="historyLog" class="com.web.action.HistoryLogStack" />
<interceptor-stack name="myDefStack">
<interceptor-ref name="historyLog" />
<interceptor-ref name="paramsPrepareParamsStack" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="myDefStack" />
package com.web.action;
import java.util.Date;
import java.util.Map;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
public class HistoryLogStack implements Interceptor {
/**
*
*/
private static final long serialVersionUID = -1385902554116735266L;
public void destroy() {
System.out.println("日志拦截器销毁...");
}
public void init() {
System.out.println("日志拦截器初始化...");
}
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("日志拦截器已经开始启动..");
String result = invocation.invoke();
String actionName= invocation.getAction().getClass().toString();
String method = invocation.getProxy().getMethod();
final Map <String,Object> parameters = invocation.getInvocationContext().getParameters();
System.out.println("Action: " + actionName + ", Method: " + method);
System.out.println("拦截的参数为:");
for (Map.Entry<String, Object> map : parameters.entrySet()) {
System.out.println(map.getKey() + "--" + map.getValue());
}
if(method != null && method.startsWith("save")){
System.out.println("Execute save method..." + new Date());
}
return result;
}
}
配置:
<interceptors>
<interceptor name="historyLog" class="com.web.action.HistoryLogStack" />
<interceptor-stack name="myDefStack">
<interceptor-ref name="historyLog" />
<interceptor-ref name="paramsPrepareParamsStack" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="myDefStack" />
相关文章推荐
- Struts2的标签及其自定义token拦截器的定义及配置
- 初学Struts2-自定义拦截器及其配置
- 初学Struts2-自定义拦截器及其配置
- struts2中自定义拦截器的配置
- 在struts2中配置自定义拦截器放行多个方法
- 如何配置自定义struts2拦截器
- struts2拦截器-自定义拦截器,放行某些方法(web.xml配置)
- Struts2 自定义拦截器配置和使用
- 电商项目笔记之一:复杂一些的struts2配置(自定义拦截器)
- struts2配置自定义拦截器
- struts2中自定义拦截器intercept的相关配置及使用方法
- struts2自定义拦截器并配置拦截器使其生效
- struts2自定义拦截器注解配置方法
- struts2的自定义拦截器和配置
- Struts2重新学习之自定义拦截器(判断用户是否是登录状态)
- Struts2拦截器Interceptor的原理与配置实例详解
- Struts2 拦截器处理同步(普通Http)请求和异步(post,ajax)请求时拦截配置
- Struts2 自定义拦截器(方法拦截器)
- Struts2自定义拦截器实例—Session超时的处理
- struts2 文件上传 拦截器的错误配置导致的问题