struts2自定义拦截器及其配置(备份)

代码:

 

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" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值