当前位置:首页 > 开发 > 系统架构 > 架构 > 正文

struts1实现aop

发表于: 2010-12-28   作者:Dead_knight   来源:转载   浏览:
摘要: 项目05年正式上线,所用struts框架版本较低,在此环境实现aop的方法如下: 步骤一:下载saif插件,放置到WEB-INF\lib下面。见附件 步骤二:在struts-config.xml中配置 <plug-in className="net.sf.struts.saif.SAIFPlugin"> <set-propert
项目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.");
	}
}

struts1实现aop

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号