myinterceptor.java

来自「Struts+Spring开发」· Java 代码 · 共 46 行

JAVA
46
字号
package org.ssi.interceptor;

import java.util.Map;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.opensymphony.xwork2.interceptor.PreResultListener;

public class MyInterceptor implements Interceptor {
	private static Logger logger = Logger.getLogger(MyInterceptor.class);

	public void destroy() {
		// TODO Auto-generated method stub

	}

	public void init() {
		// TODO Auto-generated method stub

	}

	public String intercept(ActionInvocation invocation) throws Exception {

		invocation.addPreResultListener(new PreResultListener() {

			public void beforeResult(ActionInvocation invocation,
					String resultCode) {
				Map resultsMap = invocation.getProxy().getConfig().getResults();
				ResultConfig finalResultConfig = (ResultConfig) resultsMap
						.get(resultCode);
				logger.info("***************MyInterceptor:"
						+ finalResultConfig.getName());
				// do something interesting with the 'to-be' executed result

			}

		});

		return invocation.invoke();
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?