struts1实现aop
项目05年正式上线,所用struts框架版本较低,在此环境实现aop的方法如下:
步骤一:下载saif插件,放置到WEB-INF\lib下面。见附件
步骤二:在struts-config.xml中配置
步骤三:在WEB-INF目录中增加文件interceptor-config.xml
步骤四:实现拦截器ActionInterceptorimport 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.");}}