struts1实现aop

项目05年正式上线,所用struts框架版本较低,在此环境实现aop的方法如下:
步骤一:下载saif插件,放置到WEB-INF\lib下面。见附件

步骤二:在struts-config.xml中配置
  <plug-in className="net.sf.struts.saif.SAIFPlugin">
    <set-property property="interceptor-config" 
        value="/WEB-INF/interceptor-config.xml" />
  </plug-in>


步骤三:在WEB-INF目录中增加文件interceptor-config.xml
<?xml version="1.0"?>
<interceptor-config>
 <interceptor name="LoggerManagerInterceptor" type="com.huawei.netforce.log.interceptor.LoggerManagerInterceptor"/>
 <default-interceptors>
  <interceptor name="LoggerManagerInterceptor"/>
 </default-interceptors>
</interceptor-config>


步骤四:实现拦截器ActionInterceptor
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import net.sf.struts.saif.ActionInterceptor;

public class LoggerManagerInterceptor implements ActionInterceptor
{
	private static final Logger logger = Logger.getLogger(LoggerManagerInterceptor.class);
    
    	public void beforeAction(Action action, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	{
		logger.debug("LoggerManagerInterceptor before execute");
		logger.debug("LoggerManagerInterceptor before execute End.");
	}

	public void afterAction(Action action, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	{
		System.out.println("LoggerManagerInterceptor After execute");
		System.out.println("LoggerManagerInterceptor After execute End.");
	}
}

你可能感兴趣的:(apache,AOP,xml,log4j,struts)