struts1实现aop_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > struts1实现aop

struts1实现aop

 2010/12/29 8:11:00  Dead_knight  http://dead-knight.javaeye.com  我要评论(0)
  • 摘要:项目05年正式上线,所用struts框架版本较低,在此环境实现aop的方法如下:步骤一:下载saif插件,放置到WEB-INF\lib下面。见附件步骤二:在struts-config.xml中配置<plug-inclassName="net.sf.struts.saif.SAIFPlugin"><set-propertyproperty="interceptor-config"value="/WEB-INF/interceptor-config.xml"/><
  • 标签:实现 struts
项目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.");
	}
}
发表评论
用户名: 匿名