LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 3684|回复: 10

Struts拦截器v0.2 for Struts+spring

[复制链接]
发表于 2005-8-19 09:05:29 | 显示全部楼层 |阅读模式
需组合使用Struts和Spring,支持Struts Action、DispatchAction。
支持default-interceptors,支持interceptor-stacks,支持自定义执行顺序,支持default-interceptors排除。拦截器需要在Spring里面定义成bean。
配置文件样本如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- version 0.2 -->
  3. <!-- inception class definition in spring config files [applicationContext-strutsinterceptor.xml] -->
  4. <!-- interceptor in SSH(Struts+Spring+Hibernate) created by LJ-silver-->
  5. <!-- new interceptor config -->
  6. <struts-interceptor>

  7.         <config>
  8.                 <!-- definition need order or not, default is false-->
  9.                 <order-interceptor value="true" />
  10.         </config>

  11.         <!-- definition default interceptor [last-order default value is false]-->
  12.         <default-interceptors>
  13.                 <!-- <default-interceptor order="1" last-order="false"
  14.                         bean="loginInterceptor" />
  15.                         <default-interceptor order="2" last-order="false"
  16.                         bean="adminInterceptor" /> -->
  17.                 <default-interceptor order="3" last-order="false"
  18.                         bean="printInfoInterceptor" />
  19.                 <default-interceptor order="4" last-order="false"
  20.                         bean="processDatabaseExceptionInterceptor" />
  21.         </default-interceptors>

  22.         <!-- definition interceptor stack-->
  23.         <interceptor-stacks>
  24.                 <!--        <interceptor-stack name="other">
  25.                         <interceptor-ref name="" order="1" />
  26.                         <interceptor-ref name="" order="2" />
  27.                         </interceptor-stack> -->
  28.         </interceptor-stacks>

  29.         <!-- setup action interceptor -->
  30.         <action-interceptors>
  31.                 <!-- <action path="/product/loginT">
  32.                         <exclude-default all="false">
  33.                         <exclude name="loginInterceptor" />
  34.                         <exclude name="adminInterceptor" />
  35.                         </exclude-default>
  36.                         </action>
  37.                         <action path="/product/loginF">
  38.                         <exclude-default all="false">
  39.                         <exclude name="loginInterceptor" />
  40.                         <exclude name="adminInterceptor" />
  41.                         </exclude-default>
  42.                         </action> -->
  43.                 <action path="/product/classF">
  44.                         <exclude-default all="true"></exclude-default>
  45.                         <method name="add">
  46.                                 <interceptor-ref name="loginInterceptor" />
  47.                         </method>
  48.                 </action>
  49.                 <!--  
  50.                         <action path="/product/loginT">
  51.                         <method name="login,prepare">
  52.                         <interceptor-ref order="1" name="login" />
  53.                         <interceptor-ref order="2" name="savevotepermission" />
  54.                         <stack-ref order="3" name="other" />
  55.                         </method>
  56.                         <method name="execute">
  57.                         <interceptor-ref order="1" name="login" />
  58.                         </method>
  59.                         <method name="logout">
  60.                         <exclude-default all="false">
  61.                         <exclude name="" />
  62.                         </exclude-default>
  63.                         </method>
  64.                         </action>-->
  65.                 <!--
  66.                         <action path="/example/memberT">
  67.                         <exclude-default all="false">
  68.                         <exclude name="" />
  69.                         </exclude-default>
  70.                         </action> -->
  71.         </action-interceptors>

  72. </struts-interceptor>

复制代码
 楼主| 发表于 2005-8-19 09:06:40 | 显示全部楼层

拦截器接口


  1. /*
  2. * 创建日期 2005-3-31
  3. *
  4. */
  5. package com.bupticet.strutsinterceptor;

  6. import javax.servlet.http.HttpServletRequest;
  7. import javax.servlet.http.HttpServletResponse;

  8. import org.apache.struts.action.Action;
  9. import org.apache.struts.action.ActionForm;
  10. import org.apache.struts.action.ActionForward;
  11. import org.apache.struts.action.ActionMapping;

  12. /**
  13. * <p>
  14. * Title: ActionInterceptor
  15. * </p>
  16. * <p>
  17. * Description: 拦截器接口
  18. * </p>
  19. * <p>
  20. * Copyright: Copyright (c)北京邮电大学网络教育技术研究所[[url]www.buticet.com][/url] 2005
  21. * </p>
  22. * <p>
  23. * Company: 北京邮电大学网络教育技术研究所[[url]www.buticet.com][/url]
  24. * </p>
  25. *
  26. * @author LJ-silver E-mail:LJ-silver@163.com
  27. * @version 1.0
  28. */
  29. public interface ActionInterceptor {
  30.         /**
  31.          * Called before an action is executed
  32.          *
  33.          * @param action
  34.          * @param mapping
  35.          * @param form
  36.          * @param request
  37.          * @param response
  38.          * @return ActionForward
  39.          * @throws Exception
  40.          */
  41.         public ActionForward beforeAction(Action action, ActionMapping mapping,
  42.                         ActionForm form, HttpServletRequest request,
  43.                         HttpServletResponse response) throws Exception;

  44.         /**
  45.          * Called after an action is executed
  46.          *
  47.          * @param action
  48.          * @param mapping
  49.          * @param form
  50.          * @param request
  51.          * @param response
  52.          * @return ActionForward
  53.          * @throws Exception
  54.          */
  55.         public ActionForward afterAction(Action action, ActionMapping mapping,
  56.                         ActionForm form, HttpServletRequest request,
  57.                         HttpServletResponse response) throws Exception;

  58.         /**
  59.          * Called when exception is throwed
  60.          *
  61.          * @param action
  62.          * @param mapping
  63.          * @param form
  64.          * @param request
  65.          * @param response
  66.          * @param e
  67.          * @return ActionForward
  68.          * @throws Exception
  69.          */
  70.         public ActionForward throwsAction(Action action, ActionMapping mapping,
  71.                         ActionForm form, HttpServletRequest request,
  72.                         HttpServletResponse response, Exception e) throws Exception;
  73. }

复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-19 09:07:32 | 显示全部楼层

ActionInterceptor的抽象实现,编写ActionInterceptor一般扩展本类


  1. /**
  2. * 创建日期 2005-8-14
  3. */
  4. package com.bupticet.strutsinterceptor;

  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;

  7. import org.apache.struts.action.Action;
  8. import org.apache.struts.action.ActionForm;
  9. import org.apache.struts.action.ActionForward;
  10. import org.apache.struts.action.ActionMapping;

  11. import com.bupticet.base.web.action.BaseActionUtils;

  12. /**
  13. * <p>
  14. * Title:AbstractActionInterceptor
  15. * </p>
  16. * <p>
  17. * Description:ActionInterceptor的抽象实现,编写ActionInterceptor一般扩展本类
  18. * </p>
  19. * <p>
  20. * Copyright:Copyright (c) 北京邮电大学网络教育技术研究所 (Institute of Cyber-Educational
  21. * Technology of Beijing University of Posts and
  22. * Telecommunications),[[url]www.bupticet.com][/url] 2005
  23. * </p>
  24. * <p>
  25. * Company:北京邮电大学网络教育技术研究所 (Institute of Cyber-Educational Technology of Beijing
  26. * University of Posts and Telecommunications),[[url]www.bupticet.com][/url]
  27. * </p>
  28. *
  29. * @author LJ-silver
  30. * @version
  31. */
  32. public class AbstractActionInterceptor extends BaseActionUtils implements ActionInterceptor {

  33.         /*
  34.          * (non-Javadoc)
  35.          *
  36.          * @see com.bupticet.strutsinterceptor.ActionInterceptor#beforeAction(org.apache.struts.action.Action,
  37.          *      org.apache.struts.action.ActionMapping,
  38.          *      org.apache.struts.action.ActionForm,
  39.          *      javax.servlet.http.HttpServletRequest,
  40.          *      javax.servlet.http.HttpServletResponse)
  41.          */
  42.         public ActionForward beforeAction(Action action, ActionMapping mapping,
  43.                         ActionForm form, HttpServletRequest request,
  44.                         HttpServletResponse response) throws Exception {
  45.                 return null;
  46.         }

  47.         /*
  48.          * (non-Javadoc)
  49.          *
  50.          * @see com.bupticet.strutsinterceptor.ActionInterceptor#afterAction(org.apache.struts.action.Action,
  51.          *      org.apache.struts.action.ActionMapping,
  52.          *      org.apache.struts.action.ActionForm,
  53.          *      javax.servlet.http.HttpServletRequest,
  54.          *      javax.servlet.http.HttpServletResponse)
  55.          */
  56.         public ActionForward afterAction(Action action, ActionMapping mapping,
  57.                         ActionForm form, HttpServletRequest request,
  58.                         HttpServletResponse response) throws Exception {
  59.                 return null;
  60.         }

  61.         /*
  62.          * (non-Javadoc)
  63.          *
  64.          * @see com.bupticet.strutsinterceptor.ActionInterceptor#throwsAction(org.apache.struts.action.Action,
  65.          *      org.apache.struts.action.ActionMapping,
  66.          *      org.apache.struts.action.ActionForm,
  67.          *      javax.servlet.http.HttpServletRequest,
  68.          *      javax.servlet.http.HttpServletResponse, java.lang.Exception)
  69.          */
  70.         public ActionForward throwsAction(Action action, ActionMapping mapping,
  71.                         ActionForm form, HttpServletRequest request,
  72.                         HttpServletResponse response, Exception e) throws Exception {
  73.                 return null;
  74.         }
  75. }

复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-19 09:08:39 | 显示全部楼层

配置文件读取类


  1. /*
  2. * 创建日期 2005-3-31
  3. *
  4. */
  5. package com.bupticet.strutsinterceptor;

  6. import java.io.File;
  7. import java.io.IOException;
  8. import java.util.ArrayList;
  9. import java.util.Collection;
  10. import java.util.Collections;
  11. import java.util.HashMap;
  12. import java.util.Iterator;
  13. import java.util.List;
  14. import java.util.Map;

  15. import javax.servlet.http.HttpServletRequest;

  16. import org.apache.commons.digester.Digester;
  17. import org.apache.log4j.Logger;
  18. import org.apache.struts.config.ActionConfig;
  19. import org.springframework.web.context.WebApplicationContext;
  20. import org.xml.sax.SAXException;

  21. import com.bupticet.base.AbstractBaseObject;
  22. import com.bupticet.strutsinterceptor.model.ActionModel;
  23. import com.bupticet.strutsinterceptor.model.DefaultInterceptorModel;
  24. import com.bupticet.strutsinterceptor.model.ExcludeDefaultModel;
  25. import com.bupticet.strutsinterceptor.model.ExcludeModel;
  26. import com.bupticet.strutsinterceptor.model.InterceptorRefModel;
  27. import com.bupticet.strutsinterceptor.model.InterceptorStackModel;
  28. import com.bupticet.strutsinterceptor.model.MethodModel;
  29. import com.bupticet.strutsinterceptor.model.OrderInterceptorModel;
  30. import com.bupticet.strutsinterceptor.model.StackRefModel;
  31. import com.bupticet.strutsinterceptor.model.StrutsInterceptorModel;
  32. import com.bupticet.util.FileUtils;

  33. /**
  34. * <p>
  35. * Title: InterceptorConfig
  36. * </p>
  37. * <p>
  38. * Description: 配置文件读取类
  39. * </p>
  40. * <p>
  41. * Copyright: Copyright (c)北京邮电大学网络教育技术研究所[[url]www.buticet.com][/url] 2005
  42. * </p>
  43. * <p>
  44. * Company: 北京邮电大学网络教育技术研究所[[url]www.buticet.com][/url]
  45. * </p>
  46. *
  47. * @author LJ-silver E-mail:LJ-silver@163.com
  48. * @version 1.0
  49. */
  50. public class InterceptorConfig {
  51.         /**
  52.          * Logger for this class
  53.          */
  54.         private static final Logger logger = Logger
  55.                         .getLogger(InterceptorConfig.class);

  56.         private static StrutsInterceptorModel strutsInterceptor;

  57.         private static Map methodConfig;

  58.         private static Map actionConfig;

  59.         private static long modifyTime;

  60.         private static String absolutePath;

  61.         private static WebApplicationContext wac;

  62.         private final static String filePathName = "/config/strutsinterceptor/struts-interceptor.xml";

  63.         /**
  64.          * 返回对应请求(request)的ActionInterceptor数组
  65.          *
  66.          * @param request
  67.          * @param wac
  68.          * @return ActionInterceptor[]
  69.          */
  70.         public static ActionInterceptor[] getInterceptorArray(
  71.                         HttpServletRequest request, WebApplicationContext wac) {
  72.                 ActionConfig actionConfig = (ActionConfig) request
  73.                                 .getAttribute("org.apache.struts.action.mapping.instance");
  74.                 String path = actionConfig.getPath();
  75.                 String method = null;
  76.                 if (null != actionConfig.getParameter()) {
  77.                         String parameter = actionConfig.getParameter();
  78.                         method = request.getParameter(parameter);
  79.                 } else {
  80.                         method = "execute";
  81.                 }
  82.                 return getInterceptorArray(path, method, wac);
  83.         }

  84.         /**
  85.          * 返回对应path和method的ActionInterceptor数组,[尚未实现消除重复]
  86.          *
  87.          * @param path
  88.          * @param method
  89.          * @param wac
  90.          * @return ActionInterceptor[]
  91.          */
  92.         public static ActionInterceptor[] getInterceptorArray(String path,
  93.                         String method, WebApplicationContext wac) {
  94.                 init(wac);
  95.                 List list = getInterceptorList(path, method);
  96.                 int size = list.size();
  97.                 ActionInterceptor[] arrays = new ActionInterceptor[size];
  98.                 for (int i = 0; i < size; i++) {
  99.                         arrays[i] = (ActionInterceptor) list.get(i);
  100.                 }
  101.                 return arrays;
  102.         }

  103.         /**
  104.          * 返回对应path和method的bean List
  105.          *
  106.          * @param path
  107.          * @param method
  108.          * @return List
  109.          */
  110.         private static List getInterceptorList(String path, String method) {
  111.                 List interceptorName = null;
  112.                 if (methodConfig.containsKey(new PathNMethod(path, method))) {
  113.                         interceptorName = (List) methodConfig.get(new PathNMethod(path,
  114.                                         method));
  115.                 } else if (actionConfig.containsKey(path)) {
  116.                         interceptorName = (List) actionConfig.get(path);
  117.                 } else {
  118.                         interceptorName = getDefaultInterceptors(strutsInterceptor
  119.                                         .isOrderInterceptor());
  120.                 }
  121.                 List interceptorClass = new ArrayList();
  122.                 for (int i = 0; i < interceptorName.size(); i++) {
  123.                         String name = (String) interceptorName.get(i);
  124.                         Object bean = wac.getBean(name);
  125.                         if (bean == null) {
  126.                                 throw new RuntimeException("在spring容器中找不到:" + name + "!");
  127.                         }
  128.                         interceptorClass.add(bean);
  129.                 }
  130.                 return interceptorClass;
  131.         }

  132.         /**
  133.          * @param b
  134.          * @return List
  135.          */
  136.         private static List getDefaultInterceptors(boolean b) {
  137.                 List l = new ArrayList();
  138.                 if (b) {
  139.                         if (strutsInterceptor.getFirstOrderDefaultInterceptors() != null
  140.                                         && strutsInterceptor.getFirstOrderDefaultInterceptors()
  141.                                                         .size() != 0) {
  142.                                 addDefaultInterceptorsCollection(l, strutsInterceptor
  143.                                                 .getFirstOrderDefaultInterceptors());
  144.                         }
  145.                         if (strutsInterceptor.getLastOrderDefaultInterceptors() != null
  146.                                         && strutsInterceptor.getLastOrderDefaultInterceptors()
  147.                                                         .size() != 0) {
  148.                                 addDefaultInterceptorsCollection(l, strutsInterceptor
  149.                                                 .getLastOrderDefaultInterceptors());
  150.                         }
  151.                 } else {
  152.                         Collection collection = strutsInterceptor.getDefaultInterceptors()
  153.                                         .values();
  154.                         if (collection != null && collection.size() != 0) {
  155.                                 addDefaultInterceptorsCollection(l, collection);
  156.                         }
  157.                 }
  158.                 return l;
  159.         }

  160.         /**
  161.          * 加入包含DefaultInterceptorModel模型的DefaultInterceptorsCollection
  162.          *
  163.          * @param l
  164.          * @param c
  165.          */
  166.         private static void addDefaultInterceptorsCollection(List l, Collection c) {
  167.                 if (c == null || c.size() == 0) {
  168.                         return;
  169.                 } else {
  170.                         for (Iterator it = c.iterator(); it.hasNext();) {
  171.                                 DefaultInterceptorModel model = (DefaultInterceptorModel) it
  172.                                                 .next();
  173.                                 l.add(model.getBean());
  174.                         }
  175.                 }
  176.         }

  177.         /**
  178.          * 判断是否需要载入或者重新载入配置文件并执行
  179.          *
  180.          * @param wac
  181.          */
  182.         private static synchronized void init(WebApplicationContext wac) {
  183.                 if (InterceptorConfig.wac == null) {
  184.                         InterceptorConfig.wac = wac;
  185.                 }
  186.                 if (methodConfig == null || actionConfig == null) {
  187.                         initResource();
  188.                 } else if (new File(absolutePath).lastModified() != modifyTime) {
  189.                         initResource();
  190.                 } else {
  191.                         return;
  192.                 }
  193.         }

  194.         /**
  195.          * 载入或者重新载入配置文件
  196.          */
  197.         private static void initResource() {
  198.                 if (absolutePath == null) {
  199.                         absolutePath = FileUtils.getAbsolutePath(InterceptorConfig.class,
  200.                                         filePathName);
  201.                 }
  202.                 File file = new File(absolutePath);
  203.                 modifyTime = file.lastModified();
  204.                 readConfig();
  205.                 checkStackBeanExists();
  206.                 checkDefaultBeanExists();
  207.                 if (strutsInterceptor.isOrderInterceptor()) {
  208.                         prepareSort();
  209.                 }
  210.                 buildConfig();
  211.                 // 清理无用缓存
  212.                 strutsInterceptor.setInterceptorStacks(null);
  213.                 strutsInterceptor.setActions(null);
  214.         }

  215.         /**
  216.          * 构建配置
  217.          */
  218.         private static void buildConfig() {
  219.                 try {
  220.                         Map methodMap = new HashMap();
  221.                         Map actionMap = new HashMap();
  222.                         List actions = strutsInterceptor.getActions();
  223.                         for (int i = 0; i < actions.size(); i++) {
  224.                                 ActionModel action = (ActionModel) actions.get(i);
  225.                                 ExcludeDefaultModel actionExclude = action.getExcludeDefault();
  226.                                 checkRefDefault(actionExclude);
  227.                                 List methodsList = action.getMethods();
  228.                                 Collection collection = strutsInterceptor
  229.                                                 .getDefaultInterceptors().values();

  230.                                 for (int j = 0; j < methodsList.size(); j++) {
  231.                                         MethodModel method = (MethodModel) methodsList.get(j);
  232.                                         String[] methodArray = method.getNameArray();
  233.                                         if (methodArray.length == 0) {
  234.                                                 throw new RuntimeException(
  235.                                                                 "method name不能为空,action name:"
  236.                                                                                 + action.getPath());
  237.                                         }
  238.                                         ExcludeDefaultModel methodExclude = method
  239.                                                         .getExcludeDefault();
  240.                                         checkRefDefault(methodExclude);
  241.                                         if (actionExclude != null
  242.                                                         && actionExclude.getExcludes().size() != 0) {
  243.                                                 if (methodExclude == null) {
  244.                                                         methodExclude = new ExcludeDefaultModel();
  245.                                                 }
  246.                                                 methodExclude.getExcludes().addAll(
  247.                                                                 actionExclude.getExcludes());
  248.                                         }
  249.                                         String methodName = methodArray[0];
  250.                                         List interceptorName = new ArrayList();

  251.                                         if (strutsInterceptor.isOrderInterceptor()) {
  252.                                                 if ((actionExclude == null || !actionExclude.isAll())
  253.                                                                 && (methodExclude == null || !methodExclude
  254.                                                                                 .isAll())) {
  255.                                                         addUnExcludeInterceptor(
  256.                                                                         interceptorName,
  257.                                                                         strutsInterceptor
  258.                                                                                         .getFirstOrderDefaultInterceptors(),
  259.                                                                         methodExclude);
  260.                                                 }
  261.                                                 List interceptorRefs = method.getInterceptorRefs();
  262.                                                 List stackRefs = method.getStackRefs();
  263.                                                 addRefs(interceptorName, interceptorRefs, stackRefs,
  264.                                                                 true);
  265.                                                 if ((actionExclude == null || !actionExclude.isAll())
  266.                                                                 && (methodExclude == null || !methodExclude
  267.                                                                                 .isAll())) {
  268.                                                         addUnExcludeInterceptor(interceptorName,
  269.                                                                         strutsInterceptor
  270.                                                                                         .getLastOrderDefaultInterceptors(),
  271.                                                                         methodExclude);
  272.                                                 }

  273.                                         } else {
  274.                                                 if ((actionExclude == null || !actionExclude.isAll())
  275.                                                                 && (methodExclude == null || !methodExclude
  276.                                                                                 .isAll())) {
  277.                                                         if (collection != null && collection.size() != 0) {
  278.                                                                 List defaultInterceptors = new ArrayList();
  279.                                                                 defaultInterceptors.addAll(collection);
  280.                                                                 addUnExcludeInterceptor(interceptorName,
  281.                                                                                 defaultInterceptors, methodExclude);
  282.                                                         }

  283.                                                 }
  284.                                                 List interceptorRefs = method.getInterceptorRefs();
  285.                                                 List stackRefs = method.getStackRefs();
  286.                                                 addRefs(interceptorName, interceptorRefs, stackRefs,
  287.                                                                 false);
  288.                                         }
  289.                                         if (interceptorName == null) {
  290.                                                 interceptorName = new ArrayList();
  291.                                         }
  292.                                         if (methodMap.containsKey(new PathNMethod(action.getPath(),
  293.                                                         methodName))) {
  294.                                                 throw new RuntimeException("method重复定义,action="
  295.                                                                 + action.getPath() + " , method=" + methodName);
  296.                                         } else {
  297.                                                 methodMap.put(new PathNMethod(action.getPath(),
  298.                                                                 methodName), interceptorName);
  299.                                         }

  300.                                         if (methodArray.length > 1) {
  301.                                                 for (int k = 1; k < methodArray.length; k++) {
  302.                                                         if (methodMap.containsKey(new PathNMethod(action
  303.                                                                         .getPath(), methodName))) {
  304.                                                                 throw new RuntimeException("method重复定义,action="
  305.                                                                                 + action.getPath() + " , method="
  306.                                                                                 + methodName);
  307.                                                         } else {
  308.                                                                 methodMap.put(new PathNMethod(action.getPath(),
  309.                                                                                 methodArray[k]), interceptorName);
  310.                                                         }

  311.                                                 }
  312.                                         }
  313.                                 }
  314.                                 List actionInterceptorName = new ArrayList();
  315.                                 if (strutsInterceptor.isOrderInterceptor()) {
  316.                                         if (actionExclude == null || !actionExclude.isAll()) {
  317.                                                 addUnExcludeInterceptor(actionInterceptorName,
  318.                                                                 strutsInterceptor
  319.                                                                                 .getFirstOrderDefaultInterceptors(),
  320.                                                                 actionExclude);
  321.                                                 addUnExcludeInterceptor(actionInterceptorName,
  322.                                                                 strutsInterceptor
  323.                                                                                 .getLastOrderDefaultInterceptors(),
  324.                                                                 actionExclude);
  325.                                         }
  326.                                 } else {
  327.                                         if (actionExclude == null || !actionExclude.isAll()) {
  328.                                                 if (collection != null && collection.size() != 0) {
  329.                                                         List defaultInterceptors = new ArrayList();
  330.                                                         defaultInterceptors.addAll(collection);
  331.                                                         addUnExcludeInterceptor(actionInterceptorName,
  332.                                                                         defaultInterceptors, actionExclude);
  333.                                                 }

  334.                                         }
  335.                                 }
  336.                                 if (actionMap.containsKey(action.getPath())) {
  337.                                         throw new RuntimeException("action重复定义,action="
  338.                                                         + action.getPath());
  339.                                 } else {
  340.                                         actionMap.put(action.getPath(), actionInterceptorName);
  341.                                 }
  342.                         }
  343.                         methodConfig = methodMap;
  344.                         actionConfig = actionMap;
  345.                 } catch (Exception e) {
  346.                         e.printStackTrace();
  347.                 }
  348.         }

  349.         /**
  350.          * 加入引用的interceptor和stack
  351.          *
  352.          * @param interceptorName
  353.          * @param interceptorRefs
  354.          * @param stackRefs
  355.          * @param order
  356.          */
  357.         private static void addRefs(List interceptorName, List interceptorRefs,
  358.                         List stackRefs, boolean order) {
  359.                 Map stacks = strutsInterceptor.getInterceptorStacks();
  360.                 if (interceptorRefs == null) {
  361.                         interceptorRefs = new ArrayList();
  362.                 }
  363.                 if (stackRefs != null && stackRefs.size() != 0) {
  364.                         interceptorRefs.addAll(stackRefs);
  365.                 }
  366.                 Collections.sort(interceptorRefs);
  367.                 for (int q = 0; q < interceptorRefs.size(); q++) {
  368.                         InterceptorRefModel icpor = (InterceptorRefModel) interceptorRefs
  369.                                         .get(q);
  370.                         String icporName = icpor.getName();
  371.                         if (icpor instanceof StackRefModel) {
  372.                                 checkRefStack(icporName);
  373.                                 addStack(interceptorName, icporName);
  374.                         } else {
  375.                                 checkBeanExists(icporName);
  376.                                 interceptorName.add(icporName);
  377.                         }
  378.                 }
  379.         }

  380.         /**
  381.          * 将指定名称的stack加入
  382.          *
  383.          * @param list
  384.          * @param stackName
  385.          */
  386.         private static void addStack(List list, String stackName) {
  387.                 InterceptorStackModel stack = (InterceptorStackModel) strutsInterceptor
  388.                                 .getInterceptorStacks().get(stackName);
  389.                 List refs = stack.getInterceptorRefs();
  390.                 if (refs == null || refs.size() == 0) {
  391.                         return;
  392.                 }
  393.                 for (int i = 0; i < refs.size(); i++) {
  394.                         InterceptorRefModel model = (InterceptorRefModel) refs.get(i);
  395.                         list.add(model.getName());
  396.                 }
  397.         }

  398.         /**
  399.          * 向list中加入未被排除的defaultInterceptor
  400.          *
  401.          * @param list
  402.          * @param defaultInterceptor
  403.          * @param exclude
  404.          */
  405.         private static void addUnExcludeInterceptor(List list,
  406.                         List defaultInterceptor, ExcludeDefaultModel exclude) {
  407.                 if (exclude == null || exclude.getExcludes().size() == 0) {
  408.                         list.addAll(defaultInterceptor);
  409.                 } else {
  410.                         List excludeList = exclude.getExcludes();
  411.                         for (int i = 0; i < defaultInterceptor.size(); i++) {
  412.                                 DefaultInterceptorModel model = (DefaultInterceptorModel) defaultInterceptor
  413.                                                 .get(i);
  414.                                 String beanName = model.getBean();
  415.                                 if (!excludeList.contains(beanName)) {
  416.                                         list.add(beanName);
  417.                                 }
  418.                         }
  419.                 }
  420.         }

  421.         /**
  422.          * 预排序
  423.          */
  424.         private static void prepareSort() {
  425.                 strutsInterceptor.sortDefaultInterceptors();
  426.                 strutsInterceptor.sortInterceptorStacks();
  427.         }

  428.         /**
  429.          * 检查在spring容器中是否存在bean
  430.          *
  431.          * @param beanName
  432.          */
  433.         private static void checkBeanExists(String beanName) {
  434.                 if (!wac.containsBean(beanName)) {
  435.                         throw new RuntimeException("在spring容器中找不到:" + beanName + "!");
  436.                 }
  437.         }

  438.         /**
  439.          * 检查default-interceptor中引用的interceptor是否存在
  440.          */
  441.         private static void checkDefaultBeanExists() {
  442.                 Collection collection = strutsInterceptor.getDefaultInterceptors()
  443.                                 .values();
  444.                 if (collection == null || collection.size() == 0) {
  445.                         return;
  446.                 } else {
  447.                         for (Iterator it = collection.iterator(); it.hasNext();) {
  448.                                 DefaultInterceptorModel model = (DefaultInterceptorModel) it
  449.                                                 .next();
  450.                                 if (model == null) {
  451.                                         throw new RuntimeException("default-interceptor定义错误!");
  452.                                 } else {
  453.                                         checkBeanExists(model.getBean());
  454.                                 }
  455.                         }
  456.                 }
  457.         }

  458.         /**
  459.          * 检查stack中引用的interceptor是否存在
  460.          */
  461.         private static void checkStackBeanExists() {
  462.                 Collection collection = strutsInterceptor.getInterceptorStacks()
  463.                                 .values();
  464.                 if (collection == null || collection.size() == 0) {
  465.                         return;
  466.                 } else {
  467.                         for (Iterator it = collection.iterator(); it.hasNext();) {
  468.                                 InterceptorStackModel model = (InterceptorStackModel) it.next();
  469.                                 if (model == null) {
  470.                                         throw new RuntimeException("interceptor-stack定义错误!");
  471.                                 } else {
  472.                                         List refList = model.getInterceptorRefs();
  473.                                         if (refList == null || refList.size() == 0) {
  474.                                                 continue;
  475.                                         } else {
  476.                                                 for (int i = 0; i < refList.size(); i++) {
  477.                                                         InterceptorRefModel ref = (InterceptorRefModel) refList
  478.                                                                         .get(i);
  479.                                                         if (ref == null) {
  480.                                                                 throw new RuntimeException(
  481.                                                                                 "interceptor-stack中的引用定义错误,interceptor-stack name:"
  482.                                                                                                 + model.getName());
  483.                                                         }
  484.                                                         checkBeanExists(ref.getName());
  485.                                                 }
  486.                                         }
  487.                                 }
  488.                         }
  489.                 }
  490.         }

  491.         /**
  492.          * 检查interceptor-stack引用是否存在
  493.          *
  494.          * @param name
  495.          */
  496.         private static void checkRefStack(String name) {
  497.                 if (!strutsInterceptor.getInterceptorStacks().containsKey(name)) {
  498.                         throw new RuntimeException("找不到name为" + name
  499.                                         + "对应的interceptor-stack定义!");
  500.                 }
  501.         }

  502.         /**
  503.          * 检查default-interceptor引用是否存在
  504.          *
  505.          * @param name
  506.          */
  507.         private static void checkRefDefault(String name) {
  508.                 if (!strutsInterceptor.getDefaultInterceptors().containsKey(name)) {
  509.                         throw new RuntimeException("找不到name为:" + name
  510.                                         + "的default-interceptor定义!");
  511.                 }
  512.         }

  513.         /**
  514.          * 检查default-interceptor引用是否存在
  515.          *
  516.          * @param exclude
  517.          */
  518.         private static void checkRefDefault(ExcludeDefaultModel exclude) {
  519.                 if (exclude == null) {
  520.                         return;
  521.                 }
  522.                 List list = exclude.getExcludes();
  523.                 if (list == null || list.size() == 0) {
  524.                         return;
  525.                 } else {
  526.                         for (int i = 0; i < list.size(); i++) {
  527.                                 String name = (String) list.get(i);
  528.                                 checkRefDefault(name);
  529.                         }
  530.                 }
  531.         }

  532.         /**
  533.          * 读配置文件
  534.          */
  535.         private static void readConfig() {
  536.                 Digester digester = new Digester();
  537.                 StrutsInterceptorModel strutsInterceptorModel = new StrutsInterceptorModel();
  538.                 digester.push(strutsInterceptorModel);
  539.                 addDigesterRules(digester);
  540.                 try {
  541.                         File srcfile = new File(absolutePath);
  542.                         digester.parse(srcfile);
  543.                 } catch (IOException e) {
  544.                         logger.error("In readConfig(), Exception Occured ! Info :"
  545.                                         + e.getLocalizedMessage());
  546.                         throw new RuntimeException("Error reading input file:"
  547.                                         + e.getLocalizedMessage());
  548.                 } catch (SAXException e) {
  549.                         logger.error("In readConfig(), Exception Occured ! Info :"
  550.                                         + e.getLocalizedMessage());
  551.                         throw new RuntimeException("Error parsing input file:"
  552.                                         + e.getLocalizedMessage());
  553.                 }
  554.                 strutsInterceptor = strutsInterceptorModel;
  555.         }

  556.         /**
  557.          * 添加Digester Rules
  558.          *
  559.          * @param d
  560.          */
  561.         private static void addDigesterRules(Digester d) {
  562.                 // order-interceptor
  563.                 d.addObjectCreate("struts-interceptor/config/order-interceptor",
  564.                                 OrderInterceptorModel.class);
  565.                 d.addSetProperties("struts-interceptor/config/order-interceptor");
  566.                 d.addSetNext("struts-interceptor/config/order-interceptor",
  567.                                 "setOrderInterceptor");
  568.                 // default-interceptors
  569.                 d.addObjectCreate(
  570.                                 "struts-interceptor/default-interceptors/default-interceptor",
  571.                                 DefaultInterceptorModel.class);
  572.                 d
  573.                                 .addSetProperties("struts-interceptor/default-interceptors/default-interceptor");
  574.                 d.addSetNext(
  575.                                 "struts-interceptor/default-interceptors/default-interceptor",
  576.                                 "addDefaultInterceptor");
  577.                 // interceptor-stacks
  578.                 d.addObjectCreate(
  579.                                 "struts-interceptor/interceptor-stacks/interceptor-stack",
  580.                                 InterceptorStackModel.class);
  581.                 d
  582.                                 .addSetProperties("struts-interceptor/interceptor-stacks/interceptor-stack");
  583.                 d.addSetNext("struts-interceptor/interceptor-stacks/interceptor-stack",
  584.                                 "addInterceptorStackModel");
  585.                 d
  586.                                 .addObjectCreate(
  587.                                                 "struts-interceptor/interceptor-stacks/interceptor-stack/interceptor-ref",
  588.                                                 InterceptorRefModel.class);
  589.                 d
  590.                                 .addSetProperties("struts-interceptor/interceptor-stacks/interceptor-stack/interceptor-ref");
  591.                 d
  592.                                 .addSetNext(
  593.                                                 "struts-interceptor/interceptor-stacks/interceptor-stack/interceptor-ref",
  594.                                                 "addInterceptorRef");
  595.                 // action-interceptors
  596.                 d.addObjectCreate("struts-interceptor/action-interceptors/action",
  597.                                 ActionModel.class);
  598.                 d.addSetProperties("struts-interceptor/action-interceptors/action");
  599.                 d.addSetNext("struts-interceptor/action-interceptors/action",
  600.                                 "addAction");
  601.                 d
  602.                                 .addObjectCreate(
  603.                                                 "struts-interceptor/action-interceptors/action/exclude-default",
  604.                                                 ExcludeDefaultModel.class);
  605.                 d
  606.                                 .addSetProperties("struts-interceptor/action-interceptors/action/exclude-default");
  607.                 d
  608.                                 .addSetNext(
  609.                                                 "struts-interceptor/action-interceptors/action/exclude-default",
  610.                                                 "setExcludeDefault");
  611.                 d
  612.                                 .addObjectCreate(
  613.                                                 "struts-interceptor/action-interceptors/action/exclude-default/exclude",
  614.                                                 ExcludeModel.class);
  615.                 d
  616.                                 .addSetProperties("struts-interceptor/action-interceptors/action/exclude-default/exclude");
  617.                 d
  618.                                 .addSetNext(
  619.                                                 "struts-interceptor/action-interceptors/action/exclude-default/exclude",
  620.                                                 "addExclude");
  621.                 d.addObjectCreate(
  622.                                 "struts-interceptor/action-interceptors/action/method",
  623.                                 MethodModel.class);
  624.                 d
  625.                                 .addSetProperties("struts-interceptor/action-interceptors/action/method");
  626.                 d.addSetNext("struts-interceptor/action-interceptors/action/method",
  627.                                 "addMothod");
  628.                 d
  629.                                 .addObjectCreate(
  630.                                                 "struts-interceptor/action-interceptors/action/method/exclude-default",
  631.                                                 ExcludeDefaultModel.class);
  632.                 d
  633.                                 .addSetProperties("struts-interceptor/action-interceptors/action/method/exclude-default");
  634.                 d
  635.                                 .addSetNext(
  636.                                                 "struts-interceptor/action-interceptors/action/method/exclude-default",
  637.                                                 "setExcludeDefault");
  638.                 d
  639.                                 .addObjectCreate(
  640.                                                 "struts-interceptor/action-interceptors/action/method/interceptor-ref",
  641.                                                 InterceptorRefModel.class);
  642.                 d
  643.                                 .addSetProperties("struts-interceptor/action-interceptors/action/method/interceptor-ref");
  644.                 d
  645.                                 .addSetNext(
  646.                                                 "struts-interceptor/action-interceptors/action/method/interceptor-ref",
  647.                                                 "addInterceptorRef");
  648.                 d
  649.                                 .addObjectCreate(
  650.                                                 "struts-interceptor/action-interceptors/action/method/stack-ref",
  651.                                                 StackRefModel.class);
  652.                 d
  653.                                 .addSetProperties("struts-interceptor/action-interceptors/action/method/stack-ref");
  654.                 d
  655.                                 .addSetNext(
  656.                                                 "struts-interceptor/action-interceptors/action/method/stack-ref",
  657.                                                 "addStackRef");
  658.         }

  659.         /**
  660.          * <p>
  661.          * Title:PathNMethod
  662.          * </p>
  663.          * <p>
  664.          * Description:模型类
  665.          * </p>
  666.          * <p>
  667.          * Copyright:Copyright (c) 北京邮电大学网络教育技术研究所 (Institute of Cyber-Educational
  668.          * Technology of Beijing University of Posts and
  669.          * Telecommunications),[[url]www.bupticet.com][/url] 2005
  670.          * </p>
  671.          * <p>
  672.          * Company:北京邮电大学网络教育技术研究所 (Institute of Cyber-Educational Technology of
  673.          * Beijing University of Posts and Telecommunications),[[url]www.bupticet.com][/url]
  674.          * </p>
  675.          *
  676.          * @author LJ-silver
  677.          * @version
  678.          */
  679.         static class PathNMethod extends AbstractBaseObject {
  680.                 /**
  681.                  *
  682.                  */
  683.                 private static final long serialVersionUID = 3257281422610674232L;

  684.                 private String path;

  685.                 private String method;

  686.                 /**
  687.                  *
  688.                  */
  689.                 public PathNMethod() {
  690.                         super();
  691.                 }

  692.                 /**
  693.                  * @param path
  694.                  * @param method
  695.                  */
  696.                 public PathNMethod(String path, String method) {
  697.                         super();
  698.                         this.path = path;
  699.                         this.method = method;
  700.                 }

  701.                 /**
  702.                  * @return Returns the method.
  703.                  */
  704.                 public String getMethod() {
  705.                         return method;
  706.                 }

  707.                 /**
  708.                  * @param method
  709.                  *            The method to set.
  710.                  */
  711.                 public void setMethod(String method) {
  712.                         this.method = method;
  713.                 }

  714.                 /**
  715.                  * @return Returns the path.
  716.                  */
  717.                 public String getPath() {
  718.                         return path;
  719.                 }

  720.                 /**
  721.                  * @param path
  722.                  *            The path to set.
  723.                  */
  724.                 public void setPath(String path) {
  725.                         this.path = path;
  726.                 }

  727.         }

  728.         /**
  729.          * for test
  730.          *
  731.          * @param args
  732.          */
  733.         public static void main(String[] args) {
  734.                 initResource();
  735.                 StrutsInterceptorModel strutsInterceptorModel = strutsInterceptor;
  736.                 Map map = methodConfig;
  737.                 System.out.println(strutsInterceptorModel.toString());
  738.                 System.out.println(map.size());

  739.         }
  740. }

复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-19 09:09:47 | 显示全部楼层

拦截器代理Action类


  1. /*
  2. * 创建日期 2005-3-31
  3. *
  4. */
  5. package com.bupticet.strutsinterceptor;

  6. import javax.servlet.http.HttpServletRequest;
  7. import javax.servlet.http.HttpServletResponse;

  8. import org.apache.log4j.Logger;
  9. import org.apache.struts.action.Action;
  10. import org.apache.struts.action.ActionForm;
  11. import org.apache.struts.action.ActionForward;
  12. import org.apache.struts.action.ActionMapping;
  13. import org.apache.struts.util.ModuleException;
  14. import org.springframework.web.context.WebApplicationContext;
  15. import org.springframework.web.struts.DelegatingActionProxy;

  16. /**
  17. * <p>
  18. * Title: InterceptorActionProxy
  19. * </p>
  20. * <p>
  21. * Description: 拦截器代理Action类
  22. * </p>
  23. * <p>
  24. * Copyright: Copyright (c)北京邮电大学网络教育技术研究所[[url]www.buticet.com][/url] 2005
  25. * </p>
  26. * <p>
  27. * Company: 北京邮电大学网络教育技术研究所[[url]www.buticet.com][/url]
  28. * </p>
  29. *
  30. * @author LJ-silver E-mail:LJ-silver@163.com
  31. * @version 2.0
  32. */
  33. public class InterceptorActionProxy extends DelegatingActionProxy {
  34.         /**
  35.          * Logger for this class
  36.          */
  37.         private static final Logger logger = Logger
  38.                         .getLogger(InterceptorActionProxy.class);

  39.         /**
  40.          * Pass the execute call on to the Spring-managed delegate Action.
  41.          *
  42.          * @see org.springframework.web.struts.DelegatingActionProxy#getDelegateAction
  43.          */
  44.         public ActionForward execute(ActionMapping mapping, ActionForm form,
  45.                         HttpServletRequest request, HttpServletResponse response)
  46.                         throws Exception {
  47.                 WebApplicationContext wac = getWebApplicationContext(getServlet(),
  48.                                 mapping.getModuleConfig());
  49.                 Action delegateAction = getDelegateAction(mapping);
  50.                 ActionForward forward = null;
  51.                 ActionInterceptor[] interceptorArray = null;
  52.                 try {
  53.                         interceptorArray = InterceptorConfig.getInterceptorArray(request,
  54.                                         wac);
  55.                 } catch (Exception e) {
  56.                         e.printStackTrace();
  57.                         logger
  58.                                         .error("in execute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) 's beforeAction running, Exception Occured !Exception info:"
  59.                                                         + e.getLocalizedMessage());
  60.                 }
  61.                 int size = interceptorArray.length;
  62.                 boolean loggerFlag = false;
  63.                 if (logger.isInfoEnabled()) {
  64.                         loggerFlag = true;
  65.                 }
  66.                 long startBeforeTime = 0;
  67.                 long endBeforeTime = 0;
  68.                 long startRunTime = 0;
  69.                 long endRunTime = 0;
  70.                 long startAfterTime = 0;
  71.                 long endAfterTime = 0;
  72.                 long startThrowTime = 0;
  73.                 long endThrowTime = 0;
  74.                 long start = 0;
  75.                 if (size > 0) {
  76.                         if (loggerFlag) {
  77.                                 startBeforeTime = System.currentTimeMillis();
  78.                         }
  79.                         for (int i = 0; i < size; i++) {
  80.                                 if (loggerFlag) {
  81.                                         start = System.currentTimeMillis();
  82.                                 }
  83.                                 try {
  84.                                         forward = interceptorArray[i].beforeAction(delegateAction,
  85.                                                         mapping, form, request, response);
  86.                                         if (forward != null) {
  87.                                                 return forward;
  88.                                         }
  89.                                 } catch (Exception e) {
  90.                                         if (e instanceof ModuleException) {
  91.                                                 throw e;
  92.                                         }
  93.                                         if (logger.isDebugEnabled()) {
  94.                                                 logger
  95.                                                                 .debug("in execute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) 's beforeAction running, Exception Occured ! Struts Interceptor class is "
  96.                                                                                 + interceptorArray[i].getClass()
  97.                                                                                                 .getName()
  98.                                                                                 + ",Exception Info :"
  99.                                                                                 + e.getLocalizedMessage());
  100.                                         }
  101.                                         e.printStackTrace();
  102.                                         continue;
  103.                                 }
  104.                                 if (loggerFlag) {
  105.                                         logger.info(interceptorArray[i].getClass().getName()
  106.                                                         + ".beforeAction()运行时间:"
  107.                                                         + (System.currentTimeMillis() - start) + "ms!");
  108.                                 }
  109.                         }
  110.                         if (loggerFlag) {
  111.                                 endBeforeTime = System.currentTimeMillis();
  112.                         }
  113.                         try {
  114.                                 if (loggerFlag) {
  115.                                         startRunTime = System.currentTimeMillis();
  116.                                 }
  117.                                 forward = delegateAction.execute(mapping, form, request,
  118.                                                 response);
  119.                                 if (loggerFlag) {
  120.                                         endRunTime = System.currentTimeMillis();
  121.                                 }
  122.                         } catch (Exception e) {
  123.                                 if (loggerFlag) {
  124.                                         startThrowTime = System.currentTimeMillis();
  125.                                 }
  126.                                 // 如果不是ModuleException类型则进行处理
  127.                                 if (e instanceof ModuleException) {
  128.                                         throw e;
  129.                                 } else {
  130.                                         for (int i = 0; i < size; i++) {
  131.                                                 if (loggerFlag) {
  132.                                                         start = System.currentTimeMillis();
  133.                                                 }
  134.                                                 forward = interceptorArray[i].throwsAction(
  135.                                                                 delegateAction, mapping, form, request,
  136.                                                                 response, e);
  137.                                                 if (loggerFlag) {
  138.                                                         logger.info(interceptorArray[i].getClass()
  139.                                                                         .getName()
  140.                                                                         + ".throwsAction()运行时间:"
  141.                                                                         + (System.currentTimeMillis() - start)
  142.                                                                         + "ms!");
  143.                                                 }
  144.                                                 if (forward != null) {
  145.                                                         return forward;
  146.                                                 }
  147.                                         }
  148.                                         if (loggerFlag) {
  149.                                                 endThrowTime = System.currentTimeMillis();
  150.                                         }
  151.                                         e.printStackTrace();
  152.                                         logger
  153.                                                         .error("In execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response), Exception Occured ! Info :"
  154.                                                                         + e.getLocalizedMessage());
  155.                                 }
  156.                         }
  157.                         ActionForward afterForward = null;
  158.                         if (loggerFlag) {
  159.                                 startAfterTime = System.currentTimeMillis();
  160.                         }
  161.                         for (int i = 0; i < size; i++) {
  162.                                 try {
  163.                                         if (loggerFlag) {
  164.                                                 start = System.currentTimeMillis();
  165.                                         }
  166.                                         afterForward = interceptorArray[i].afterAction(
  167.                                                         delegateAction, mapping, form, request, response);
  168.                                         if (loggerFlag) {
  169.                                                 logger.info(interceptorArray[i].getClass().getName()
  170.                                                                 + ".afterAction()运行时间:"
  171.                                                                 + (System.currentTimeMillis() - start) + "ms!");
  172.                                         }
  173.                                         if (afterForward != null) {
  174.                                                 return afterForward;
  175.                                         }
  176.                                 } catch (Exception e) {
  177.                                         if (e instanceof ModuleException) {
  178.                                                 throw e;
  179.                                         }
  180.                                         e.printStackTrace();
  181.                                         if (logger.isDebugEnabled()) {
  182.                                                 logger
  183.                                                                 .debug("in execute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) 's afterAction running, Exception Occured ! Struts Interceptor class is "
  184.                                                                                 + interceptorArray[i].getClass()
  185.                                                                                                 .getName()
  186.                                                                                 + ",Exception Info :"
  187.                                                                                 + e.getLocalizedMessage());
  188.                                         }
  189.                                         continue;
  190.                                 }
  191.                         }
  192.                         if (loggerFlag) {
  193.                                 endAfterTime = System.currentTimeMillis();
  194.                         }
  195.                 } else {
  196.                         if (loggerFlag) {
  197.                                 startRunTime = System.currentTimeMillis();
  198.                         }
  199.                         forward = delegateAction.execute(mapping, form, request, response);
  200.                         if (loggerFlag) {
  201.                                 endRunTime = System.currentTimeMillis();
  202.                         }
  203.                 }
  204.                 if (loggerFlag) {
  205.                         logger.info("run before action time:"
  206.                                         + (endBeforeTime - startBeforeTime) + "ms!");
  207.                         logger.info("run action time:" + (endRunTime - startRunTime)
  208.                                         + "ms!");
  209.                         logger.info("run throw action time:"
  210.                                         + (endThrowTime - startThrowTime) + "ms!");
  211.                         logger.info("run after action time:"
  212.                                         + (endAfterTime - startAfterTime) + "ms!");
  213.                 }
  214.                 return forward;
  215.         }
  216. }

复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-19 09:10:59 | 显示全部楼层

主模型:StrutsInterceptor模型类,其它的模型暂时就不贴了


  1. /**
  2. * 创建日期 2005-8-14
  3. */
  4. package com.bupticet.strutsinterceptor.model;

  5. import java.util.ArrayList;
  6. import java.util.Collections;
  7. import java.util.HashMap;
  8. import java.util.Iterator;
  9. import java.util.List;
  10. import java.util.Map;

  11. import com.bupticet.base.AbstractBaseObject;

  12. /**
  13. * <p>
  14. * Title:StrutsInterceptorModel
  15. * </p>
  16. * <p>
  17. * Description: StrutsInterceptor模型类
  18. * </p>
  19. * <p>
  20. * Copyright:Copyright (c) 北京邮电大学网络教育技术研究所 (Institute of Cyber-Educational
  21. * Technology of Beijing University of Posts and
  22. * Telecommunications),[[url]www.bupticet.com][/url] 2005
  23. * </p>
  24. * <p>
  25. * Company:北京邮电大学网络教育技术研究所 (Institute of Cyber-Educational Technology of Beijing
  26. * University of Posts and Telecommunications),[[url]www.bupticet.com][/url]
  27. * </p>
  28. *
  29. * @author LJ-silver
  30. * @version
  31. */
  32. public class StrutsInterceptorModel extends AbstractBaseObject {

  33.         /**
  34.          *
  35.          */
  36.         private static final long serialVersionUID = 3257566196155954225L;

  37.         private boolean orderInterceptor = false;

  38.         private Map defaultInterceptors = new HashMap();

  39.         private Map interceptorStacks = new HashMap();

  40.         private List actions = new ArrayList();

  41.         private List firstOrderDefaultInterceptors;

  42.         private List lastOrderDefaultInterceptors;

  43.         /**
  44.          *
  45.          */
  46.         public StrutsInterceptorModel() {
  47.         }

  48.         /**
  49.          * @param defaultInterceptors
  50.          * @param interceptorStacks
  51.          * @param actionInterceptors
  52.          */
  53.         public StrutsInterceptorModel(Map defaultInterceptors,
  54.                         Map interceptorStacks, List actionInterceptors) {
  55.                 this.defaultInterceptors = defaultInterceptors;
  56.                 this.interceptorStacks = interceptorStacks;
  57.                 this.actions = actionInterceptors;
  58.         }

  59.         /**
  60.          * @param orderInterceptor
  61.          * @param defaultInterceptors
  62.          * @param interceptorStacks
  63.          * @param actionInterceptors
  64.          */
  65.         public StrutsInterceptorModel(boolean orderInterceptor,
  66.                         Map defaultInterceptors, Map interceptorStacks,
  67.                         List actionInterceptors) {
  68.                 this.orderInterceptor = orderInterceptor;
  69.                 this.defaultInterceptors = defaultInterceptors;
  70.                 this.interceptorStacks = interceptorStacks;
  71.                 this.actions = actionInterceptors;
  72.         }

  73.         /**
  74.          * 如果orderInterceptor为true,则对defaultInterceptors排序
  75.          */
  76.         public void sortDefaultInterceptors() {
  77.                 if (!orderInterceptor) {
  78.                         return;
  79.                 }
  80.                 firstOrderDefaultInterceptors = new ArrayList();
  81.                 lastOrderDefaultInterceptors = new ArrayList();
  82.                 for (Iterator it = defaultInterceptors.values().iterator(); it
  83.                                 .hasNext();) {
  84.                         DefaultInterceptorModel model = (DefaultInterceptorModel) it.next();
  85.                         if (model.isLastOrder()) {
  86.                                 lastOrderDefaultInterceptors.add(model);
  87.                         } else {
  88.                                 firstOrderDefaultInterceptors.add(model);
  89.                         }
  90.                 }
  91.                 Collections.sort(lastOrderDefaultInterceptors);
  92.                 Collections.sort(firstOrderDefaultInterceptors);
  93.         }

  94.         /**
  95.          * 如果orderInterceptor为true,则对interceptorStacks排序
  96.          */
  97.         public void sortInterceptorStacks() {
  98.                 if (!orderInterceptor) {
  99.                         return;
  100.                 }
  101.                 for (Iterator it = interceptorStacks.values().iterator(); it.hasNext();) {
  102.                         ((InterceptorStackModel) it.next())
  103.                                         .sortInterceptorRefs(orderInterceptor);
  104.                 }
  105.         }

  106.         /**
  107.          * @return Returns the defaultInterceptors.
  108.          */
  109.         public Map getDefaultInterceptors() {
  110.                 return defaultInterceptors;
  111.         }

  112.         /**
  113.          * @param defaultInterceptors
  114.          *            The defaultInterceptors to set.
  115.          */
  116.         public void setDefaultInterceptors(Map defaultInterceptors) {
  117.                 this.defaultInterceptors = defaultInterceptors;
  118.         }

  119.         /**
  120.          * @return Returns the interceptorStacks.
  121.          */
  122.         public Map getInterceptorStacks() {
  123.                 return interceptorStacks;
  124.         }

  125.         /**
  126.          * @param interceptorStacks
  127.          *            The interceptorStacks to set.
  128.          */
  129.         public void setInterceptorStacks(Map interceptorStacks) {
  130.                 this.interceptorStacks = interceptorStacks;
  131.         }

  132.         /**
  133.          * @return Returns the orderInterceptor.
  134.          */
  135.         public boolean isOrderInterceptor() {
  136.                 return orderInterceptor;
  137.         }

  138.         /**
  139.          * @param orderInterceptor
  140.          *            The orderInterceptor to set.
  141.          */
  142.         public void setOrderInterceptor(boolean orderInterceptor) {
  143.                 this.orderInterceptor = orderInterceptor;
  144.         }

  145.         /**
  146.          * @param model
  147.          */
  148.         public void setOrderInterceptor(OrderInterceptorModel model) {
  149.                 this.orderInterceptor = model.isValue();
  150.         }

  151.         /**
  152.          * @return Returns the actions.
  153.          */
  154.         public List getActions() {
  155.                 return actions;
  156.         }

  157.         /**
  158.          * @param actions
  159.          *            The actions to set.
  160.          */
  161.         public void setActions(List actions) {
  162.                 this.actions = actions;
  163.         }

  164.         /**
  165.          * 增加 DefaultInterceptorModel
  166.          *
  167.          * @param model
  168.          */
  169.         public void addDefaultInterceptor(DefaultInterceptorModel model) {
  170.                 String name = model.getBean();
  171.                 if (defaultInterceptors.containsKey(name)) {
  172.                         throw new RuntimeException("default-interceptor name:" + name
  173.                                         + "重复定义!");
  174.                 } else {
  175.                         defaultInterceptors.put(name, model);
  176.                 }
  177.         }

  178.         /**
  179.          * 增加 InterceptorStackModel
  180.          *
  181.          * @param model
  182.          */
  183.         public void addInterceptorStackModel(InterceptorStackModel model) {
  184.                 String name = model.getName();
  185.                 if (interceptorStacks.containsKey(name)) {
  186.                         throw new RuntimeException("interceptor-stack name:" + name
  187.                                         + "重复定义!");
  188.                 } else {
  189.                         interceptorStacks.put(name, model);
  190.                 }
  191.         }

  192.         /**
  193.          * 增加ActionModel
  194.          *
  195.          * @param model
  196.          */
  197.         public void addAction(ActionModel model) {
  198.                 this.actions.add(model);
  199.         }

  200.         /**
  201.          * @return Returns the firstOrderDefaultInterceptors.
  202.          */
  203.         public List getFirstOrderDefaultInterceptors() {
  204.                 if (firstOrderDefaultInterceptors == null) {
  205.                         this.sortDefaultInterceptors();
  206.                 }
  207.                 return firstOrderDefaultInterceptors;
  208.         }

  209.         /**
  210.          * @return Returns the lastOrderDefaultInterceptors.
  211.          */
  212.         public List getLastOrderDefaultInterceptors() {
  213.                 if (lastOrderDefaultInterceptors == null) {
  214.                         this.sortDefaultInterceptors();
  215.                 }
  216.                 return lastOrderDefaultInterceptors;
  217.         }
  218. }

复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-19 09:12:30 | 显示全部楼层

Spring配置文件中bean定义,这里还比较简单,都是独立的,如果有需要也可以在拦截器中


  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

  3. <!--
  4.         - Application context definition for bupticet project on Struts interceptor.
  5. -->
  6. <beans>
  7.         <bean id="loginInterceptor"
  8.                 class="com.bupticet.strutsinterceptor.inteceptor.LoginInterceptor">
  9.         </bean>

  10.         <bean id="adminInterceptor"
  11.                 class="com.bupticet.product.web.interceptor.AdminInterceptor">
  12.         </bean>

  13.         <bean id="printInfoInterceptor"
  14.                 class="com.bupticet.strutsinterceptor.inteceptor.PrintInfoInterceptor">
  15.         </bean>

  16.         <bean id="processDatabaseExceptionInterceptor"
  17.                 class="com.bupticet.strutsinterceptor.inteceptor.ProcessDatabaseExceptionInterceptor">
  18.         </bean>
  19. </beans>

复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-19 09:13:28 | 显示全部楼层

Struts action bean 定义


  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

  3. <!--
  4.         - Application context definition for bupticet project on Struts.
  5. -->
  6. <!-- definition action-->
  7. <beans>
  8.         <bean name="/product/dealerT"
  9.                 class="com.bupticet.product.web.action.DealerAction">
  10.                 <property name="dealerManager">
  11.                         <ref bean="dealerManager" />
  12.                 </property>
  13.         </bean>

  14.         <bean name="/product/dealerF"
  15.                 class="com.bupticet.product.web.action.DealerAction">
  16.                 <property name="dealerManager">
  17.                         <ref bean="dealerManager" />
  18.                 </property>
  19.         </bean>

  20.         <bean name="/product/fileT"
  21.                 class="com.bupticet.product.web.action.FileAction">
  22.                 <property name="fileManager">
  23.                         <ref bean="fileManager" />
  24.                 </property>
  25.         </bean>

  26.         <bean name="/product/fileF"
  27.                 class="com.bupticet.product.web.action.FileAction">
  28.                 <property name="fileManager">
  29.                         <ref bean="fileManager" />
  30.                 </property>
  31.         </bean>


  32.         <bean name="/product/faqT"
  33.                 class="com.bupticet.product.web.action.FaqAction">
  34.                 <property name="faqManager">
  35.                         <ref bean="faqManager" />
  36.                 </property>
  37.         </bean>

  38.         <bean name="/product/faqF"
  39.                 class="com.bupticet.product.web.action.FaqAction">
  40.                 <property name="faqManager">
  41.                         <ref bean="faqManager" />
  42.                 </property>
  43.         </bean>

  44.         <bean name="/product/forPageT"
  45.                 class="com.bupticet.product.web.action.ForPageAction">
  46.                 <property name="forPageManager">
  47.                         <ref bean="forPageManager" />
  48.                 </property>
  49.         </bean>

  50.         <bean name="/product/forPageF"
  51.                 class="com.bupticet.product.web.action.ForPageAction">
  52.                 <property name="forPageManager">
  53.                         <ref bean="forPageManager" />
  54.                 </property>
  55.         </bean>

  56.         <bean name="/product/friendLinksT"
  57.                 class="com.bupticet.product.web.action.FriendLinksAction">
  58.                 <property name="friendLinksManager">
  59.                         <ref bean="friendLinksManager" />
  60.                 </property>
  61.         </bean>

  62.         <bean name="/product/friendLinksF"
  63.                 class="com.bupticet.product.web.action.FriendLinksAction">
  64.                 <property name="friendLinksManager">
  65.                         <ref bean="friendLinksManager" />
  66.                 </property>
  67.         </bean>
  68.         <bean name="/product/leaveWordT"
  69.                 class="com.bupticet.product.web.action.LeaveWordAction">
  70.                 <property name="leaveWordManager">
  71.                         <ref bean="leaveWordManager" />
  72.                 </property>
  73.         </bean>

  74.         <bean name="/product/leaveWordF"
  75.                 class="com.bupticet.product.web.action.LeaveWordAction">
  76.                 <property name="leaveWordManager">
  77.                         <ref bean="leaveWordManager" />
  78.                 </property>
  79.         </bean>
  80.         <bean name="/product/loginT"
  81.                 class="com.bupticet.product.web.action.MemberAction">
  82.                 <property name="memberManager">
  83.                         <ref bean="memberManager" />
  84.                 </property>
  85.         </bean>
  86.         <bean name="/product/loginF"
  87.                 class="com.bupticet.product.web.action.MemberAction">
  88.                 <property name="memberManager">
  89.                         <ref bean="memberManager" />
  90.                 </property>
  91.         </bean>
  92.         <bean name="/product/memberT"
  93.                 class="com.bupticet.product.web.action.MemberAction">
  94.                 <property name="memberManager">
  95.                         <ref bean="memberManager" />
  96.                 </property>
  97.         </bean>
  98.         <bean name="/product/memberF"
  99.                 class="com.bupticet.product.web.action.MemberAction">
  100.                 <property name="memberManager">
  101.                         <ref bean="memberManager" />
  102.                 </property>
  103.         </bean>
  104.         <bean name="/product/typeT"
  105.                 class="com.bupticet.product.web.action.ProductTypeAction">
  106.                 <property name="productTypeManager">
  107.                         <ref bean="productTypeManager" />
  108.                 </property>
  109.         </bean>
  110.         <bean name="/product/typeF"
  111.                 class="com.bupticet.product.web.action.ProductTypeAction">
  112.                 <property name="productTypeManager">
  113.                         <ref bean="productTypeManager" />
  114.                 </property>
  115.         </bean>
  116.         <bean name="/product/classT"
  117.                 class="com.bupticet.product.web.action.ProductClassAction">
  118.                 <property name="productClassManager">
  119.                         <ref bean="productClassManager" />
  120.                 </property>
  121.         </bean>
  122.         <bean name="/product/classF"
  123.                 class="com.bupticet.product.web.action.ProductClassAction">
  124.                 <property name="productClassManager">
  125.                         <ref bean="productClassManager" />
  126.                 </property>
  127.         </bean>
  128.         <bean name="/product/productIntroT"
  129.                 class="com.bupticet.product.web.action.ProductIntroAction">
  130.                 <property name="productIntroManager">
  131.                         <ref bean="productIntroManager" />
  132.                 </property>
  133.         </bean>

  134.         <bean name="/product/productIntroF"
  135.                 class="com.bupticet.product.web.action.ProductIntroAction">
  136.                 <property name="productIntroManager">
  137.                         <ref bean="productIntroManager" />
  138.                 </property>
  139.         </bean>

  140.         <bean name="/product/productNewsT"
  141.                 class="com.bupticet.product.web.action.ProductNewsAction">
  142.                 <property name="productNewsManager">
  143.                         <ref bean="productNewsManager" />
  144.                 </property>
  145.         </bean>

  146.         <bean name="/product/productNewsF"
  147.                 class="com.bupticet.product.web.action.ProductNewsAction">
  148.                 <property name="productNewsManager">
  149.                         <ref bean="productNewsManager" />
  150.                 </property>
  151.         </bean>

  152.         <bean name="/product/voteQuestionT"
  153.                 class="com.bupticet.product.web.action.VoteQuestionAction">
  154.                 <property name="voteManager">
  155.                         <ref bean="voteManager" />
  156.                 </property>
  157.         </bean>

  158.         <bean name="/product/voteQuestionF"
  159.                 class="com.bupticet.product.web.action.VoteQuestionAction">
  160.                 <property name="voteManager">
  161.                         <ref bean="voteManager" />
  162.                 </property>
  163.         </bean>

  164.         <bean name="/product/voteOptionT"
  165.                 class="com.bupticet.product.web.action.VoteOptionAction">
  166.                 <property name="voteManager">
  167.                         <ref bean="voteManager" />
  168.                 </property>
  169.         </bean>

  170.         <bean name="/product/voteOptionF"
  171.                 class="com.bupticet.product.web.action.VoteOptionAction">
  172.                 <property name="voteManager">
  173.                         <ref bean="voteManager" />
  174.                 </property>
  175.         </bean>

  176.         <bean name="/product/dealerT"
  177.                 class="com.bupticet.product.web.action.DealerAction">
  178.                 <property name="dealerManager">
  179.                         <ref bean="dealerManager" />
  180.                 </property>
  181.         </bean>

  182.         <bean name="/product/dealerF"
  183.                 class="com.bupticet.product.web.action.DealerAction">
  184.                 <property name="dealerManager">
  185.                         <ref bean="dealerManager" />
  186.                 </property>
  187.         </bean>
  188.         <!-- definition collection for html:select-->
  189.         <bean name="typeCollection"
  190.                 class="com.bupticet.product.web.collection.TypeCollection">
  191.                 <property name="productTypeManager">
  192.                         <ref bean="productTypeManager" />
  193.                 </property>
  194.         </bean>

  195. </beans>

复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-19 09:14:54 | 显示全部楼层

struts配置文件


  1. <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
  2. <struts-config>
  3.         <form-beans>
  4.                 <form-bean name="loginForm" type="org.apache.struts.validator.DynaValidatorForm">
  5.                         <form-property name="account" type="java.lang.String" size="20" />
  6.                         <form-property name="password" type="java.lang.String" />
  7.                 </form-bean>
  8.                 <form-bean name="memberForm" type="org.apache.struts.validator.DynaValidatorForm">
  9.                         <form-property name="memberId" type="java.lang.String" size="32" />
  10.                         <form-property name="account" type="java.lang.String" size="20" />
  11.                         <form-property name="password" type="java.lang.String" />
  12.                         <form-property name="password2" type="java.lang.String" />
  13.                         <form-property name="name" type="java.lang.String" size="200" />
  14.                         <form-property name="gender" type="java.lang.Character" />
  15.                         <form-property name="email" type="java.lang.String" />
  16.                         <form-property name="telephone" type="java.lang.String" />
  17.                 </form-bean>
  18.                 <form-bean name="voteQuestionForm" type="org.apache.struts.validator.DynaValidatorForm">
  19.                         <form-property name="voteId" type="java.lang.String" size="32" />
  20.                         <form-property name="voteTitle" type="java.lang.String" size="200" />
  21.                 </form-bean>
  22.                 <form-bean name="voteOptionForm" type="org.apache.struts.validator.DynaValidatorForm">
  23.                         <form-property name="optionId" type="java.lang.String" size="32" />
  24.                         <form-property name="optionNumber" type="java.lang.String" />
  25.                         <form-property name="optionContent" type="java.lang.String" size="200" />
  26.                 </form-bean>
  27.                 <form-bean name="dealerForm" type="org.apache.struts.validator.DynaValidatorForm">
  28.                         <form-property name="dealerId" type="java.lang.String" size="32" />
  29.                         <form-property name="dealerName" type="java.lang.String" size="200" />
  30.                         <form-property name="dealerArea" type="java.lang.String" />
  31.                         <form-property name="zipCode" type="java.lang.String" size="6" />
  32.                         <form-property name="address" type="java.lang.String" />
  33.                         <form-property name="telephone" type="java.lang.String" size="30" />
  34.                         <form-property name="email" type="java.lang.String" />
  35.                         <form-property name="homepage" type="java.lang.String" />
  36.                         <form-property name="dealerIntro" type="java.lang.String" />
  37.                         <form-property name="productIntro" type="java.lang.String[]" />
  38.                 </form-bean>
  39.                 <form-bean name="friendLinksForm" type="org.apache.struts.validator.DynaValidatorForm">
  40.                         <form-property name="linkId" type="java.lang.String" size="32" />
  41.                         <form-property name="linkTitle" type="java.lang.String" size="100" />
  42.                         <form-property name="linkUrl" type="java.lang.String" />
  43.                         <form-property name="linkIntro" type="java.lang.String" />
  44.                 </form-bean>
  45.                 <form-bean name="productTypeForm" type="org.apache.struts.validator.DynaValidatorForm">
  46.                         <form-property name="typeId" type="java.lang.String" size="32" />
  47.                         <form-property name="typeName" type="java.lang.String" size="100" />
  48.                 </form-bean>
  49.                 <form-bean name="productClassForm" type="org.apache.struts.validator.DynaValidatorForm">
  50.                         <form-property name="classId" type="java.lang.String" size="32" />
  51.                         <form-property name="className" type="java.lang.String" size="100" />
  52.                         <form-property name="productTypeId" type="java.lang.String" size="32" />
  53.                 </form-bean>
  54.                 <form-bean name="productIntroForm" type="org.apache.struts.validator.DynaValidatorForm">
  55.                         <form-property name="introId" type="java.lang.String" size="32" />
  56.                         <form-property name="productName" type="java.lang.String" size="100" />
  57.                         <form-property name="productContent" type="java.lang.String" />
  58.                         <form-property name="productClassId" type="java.lang.String" size="32" />
  59.                 </form-bean>
  60.                 <form-bean name="leaveWordForm" type="org.apache.struts.validator.DynaValidatorForm">
  61.                         <form-property name="wordId" type="java.lang.String" size="32" />
  62.                         <form-property name="wordTitle" type="java.lang.String" size="100" />
  63.                         <form-property name="wordContent" type="java.lang.String" />
  64.                 </form-bean>
  65.         <form-bean name="productNewsForm" type="org.apache.struts.validator.DynaValidatorForm"><form-property name="newId" type="java.lang.String" /><form-property name="newsTitle" type="java.lang.String" /><form-property name="newsContent" type="java.lang.String" /></form-bean><form-bean name="fileForm" type="org.apache.struts.validator.DynaValidatorForm"><form-property name="file" type="org.apache.struts.upload.FormFile" /></form-bean></form-beans>
  66.         <global-exceptions>
  67.                 <exception type="org.apache.struts.util.ModuleException" key="error.noPermission" path="/product/error.jsp" scope="request" />
  68.                 <exception type="org.apache.struts.util.ModuleException" key="error.noLogin" scope="request" path="/product/error.jsp" />
  69.                 <exception type="org.apache.struts.util.ModuleException" key="error.databaseOperateError" scope="request" path="/product/error.jsp" />
  70.                 <exception type="org.apache.struts.util.ModuleException" key="error.token" path="/product/error.jsp" scope="request" />
  71.                 <exception type="org.apache.struts.util.ModuleException" key="error.illegalOperate" scope="request" path="/product/error.jsp" />
  72.                 <exception type="org.apache.struts.util.ModuleException" key="error.exception" path="/product/error.jsp" scope="request" />
  73.         </global-exceptions>
  74.         <global-forwards>
  75.                 <forward name="failure" path="/product/error.jsp" redirect="false" />
  76.                 <forward name="error" path="/product/error.jsp" redirect="false" />
  77.         </global-forwards>
  78.         <action-mappings>
  79.                 <action path="/product/loginT" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" name="loginForm" scope="request" parameter="method">
  80.                         <forward name="success" path="/product/admin_index.jsp" redirect="true" />
  81.                         <forward name="failure" path="/product/admin_login.jsp" redirect="false" />
  82.                 </action>
  83.                 <action path="/product/loginF" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy">
  84.                         <forward name="logout" path="/" redirect="false" />
  85.                         <forward name="add-success" path="/product/admin_login.jsp" redirect="false" />
  86.                 </action>
  87.                 <action path="/product/memberT" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" name="memberForm" scope="request">
  88.                         <forward name="save-success" path="/product/memberF.do?method=list" redirect="true" />
  89.                         <forward name="save-failure" path="/product/add_member.jsp" redirect="false" />
  90.                         <forward name="update-success" path="/product/memberF.do?method=view" redirect="true" />
  91.                         <forward name="update-failure" path="/product/edit_member.jsp" redirect="false" />
  92.                 </action>
  93.                 <action path="/product/memberF" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" name="memberForm" validate="false" scope="request">
  94.                         <forward name="add-success" path="/product/add_member.jsp" redirect="false" />
  95.                         <forward name="edit-success" path="/product/edit_member.jsp" redirect="false" />
  96.                         <forward name="delete-success" redirect="true" path="/product/memberF.do?method=list" />
  97.                         <forward name="delete-failure" path="/product/error.jsp" redirect="false" />
  98.                         <forward name="list-success" path="/product/list_member.jsp" redirect="false" />
  99.                         <forward name="view-success" path="/product/view_member.jsp" redirect="false" />
  100.                 </action>
  101.                 <action path="/product/friendLinksT" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" />
  102.                 <action path="/product/friendLinksF" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" />
  103.                 <action path="/product/voteQuestionT" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" name="voteQuestionForm" scope="request">
  104.                         <forward name="save-success" path="/product/list_vote_question.jsp" redirect="true" />
  105.                         <forward name="save-failure" path="/product/add_vote_question.jsp" redirect="false" />
  106.                         <forward name="update-success" path="/product/view_vote_question.jsp" redirect="true" />
  107.                         <forward name="update-failure" path="/product/edit_vote_question.jsp" redirect="false" />
  108.                         <forward name="delete-success" path="/product/list_vote_question.jsp" redirect="true" />
  109.                         <forward name="delete-failure" path="/product/error.jsp" redirect="false" />
  110.                 </action>
  111.                 <action path="/product/voteQuestionF" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy">
  112.                         <forward name="add-success" path="/product/add_vote_question.jsp" redirect="false" />
  113.                         <forward name="edit-success" path="/product/edit_vote_question.jsp" redirect="false" />
  114.                         <forward name="list-success" path="/product/list_vote_question.jsp" redirect="false" />
  115.                         <forward name="view-success" path="/product/view_vote_question.jsp" redirect="false" />
  116.                 </action>
  117.                 <action path="/product/voteOptionT" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" name="voteOptionForm" scope="request">
  118.                         <forward name="save-success" path="/product/list_vote_option.jsp" redirect="true" />
  119.                         <forward name="save-failure" path="/product/add_vote_option.jsp" redirect="false" />
  120.                         <forward name="update-success" path="/product/view_vote_option.jsp" redirect="true" />
  121.                         <forward name="update-failure" path="/product/edit_vote_option.jsp" redirect="false" />
  122.                         <forward name="delete-success" path="/product/list_vote_option.jsp" redirect="true" />
  123.                         <forward name="delete-failure" path="/product/error.jsp" redirect="false" />
  124.                 </action>
  125.                 <action path="/product/voteOptionF" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy">
  126.                         <forward name="add-success" path="/product/add_vote_option.jsp" redirect="false" />
  127.                         <forward name="edit-success" path="/product/edit_vote_option.jsp" redirect="false" />
  128.                         <forward name="view-success" path="/product/view_vote_option.jsp" redirect="false" />
  129.                 </action>
  130.                 <action path="/product/dealerT" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" name="dealerForm" scope="request">
  131.                         <forward name="save-success" path="/product/list_dealer.jsp" redirect="true" />
  132.                         <forward name="save-failure" path="/product/add_dealer.jsp" redirect="false" />
  133.                         <forward name="update-failure" path="/product/view_dealer.jsp" redirect="true" />
  134.                         <forward name="update-failure" path="/product/edit_dealer.jsp" redirect="false" />
  135.                         <forward name="delete-success" path="/product/list_dealer.jsp" redirect="true" />
  136.                         <forward name="delete-failure" path="/product/error.jsp" redirect="false" />
  137.                 </action>
  138.                 <action path="/product/dealerF" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" name="dealerForm" validate="false" scope="request">
  139.                         <forward name="add-success" path="/product/add_dealer.jsp" redirect="false" />
  140.                         <forward name="edit-success" path="/product/edit_dealer.jsp" redirect="false" />
  141.                         <forward name="view-success" path="/product/view_dealer.jsp" redirect="false" />
  142.                         <forward name="view-dealer-for-productintro-success" path="/product/view_productIntro.jsp" redirect="false" />
  143.                         <forward name="edit-dealer-for-productintro-success" path="/product/edit_productIntro.jsp" redirect="false" />
  144.                 </action>
  145.                 <action path="/product/typeF" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy">
  146.                         <forward name="add-success" path="/product/add_type.jsp" redirect="false" />
  147.                         <forward name="edit-success" path="/product/edit_type.jsp" redirect="false" />
  148.                         <forward name="delete-success" path="/product/typeF.do?method=list" redirect="true" />
  149.                         <forward name="list-success" path="/product/list_type.jsp" redirect="false" />
  150.                 </action>
  151.                 <action path="/product/typeT" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" name="productTypeForm" scope="request" validate="true">
  152.                         <forward name="save-success" redirect="true" path="/product/typeF.do?method=list" />
  153.                         <forward name="update-success" path="/product/typeF.do?method=list" redirect="true" />
  154.                 </action>
  155.                 <action path="/product/classF" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy">
  156.                         <forward name="add-success" path="/product/add_class.jsp" redirect="false" />
  157.                         <forward name="edit-success" path="/product/edit_class.jsp" redirect="false" />
  158.                         <forward name="delete-success" redirect="true" path="/product/classF.do?method=list" />
  159.                         <forward name="list-success" path="/product/list_class.jsp" redirect="false" />
  160.                 </action>
  161.                 <action path="/product/classT" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" name="productClassForm" scope="request">
  162.                         <forward name="save-success" path="/product/classF.do?method=list" redirect="true" />
  163.                         <forward name="update-success" path="/product/classF.do?method=list" redirect="false" />
  164.                 </action>
  165.                 <action path="/product/productIntroT" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" name="productIntroForm" scope="request">
  166.                         <forward name="save-success" path="/product/productIntroF.do?method=list" redirect="true" />
  167.                         <forward name="save-failure" path="/product/add_product_intro.jsp" redirect="false" />
  168.                         <forward name="update-failure" path="/product/productIntroF.do?method=view" redirect="true" />
  169.                         <forward name="update-failure" path="/product/edit_product_intro.jsp" redirect="false" />
  170.                 </action>
  171.                 <action path="/product/productIntroF" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy">
  172.                         <forward name="add-success" path="/product/add_product_intro.jsp" redirect="false" />
  173.                         <forward name="edit-success" path="/product/edit_product_intro.jsp" redirect="false" />
  174.                         <forward name="delete-success" path="/product/productIntroF.do?method=list" redirect="true" />
  175.                         <forward name="delete-failure" path="/product/error.jsp" redirect="false" />
  176.                         <forward name="list-success" path="/product/list_product_intro.jsp" redirect="false" />
  177.                         <forward name="view-success" path="/product/view_product_intro.jsp" redirect="false" />
  178.                 </action>
  179.                 <action path="/product/leaveWordT" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" name="leaveWordForm" scope="request">
  180.                         <forward name="save-success" path="/product/leaveWordF.do?method=list" redirect="true" />
  181.                         <forward name="save-failure" path="/product/add_leave_word.jsp" redirect="false" />
  182.                         <forward name="update-failure" path="/product/leaveWordF.do?method=view" redirect="true" />
  183.                         <forward name="update-failure" path="/product/edit_leave_word.jsp" redirect="false" />
  184.                 </action>
  185.                 <action path="/product/leaveWordF" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy">
  186.                         <forward name="add-success" path="/product/add_leave_word.jsp" redirect="false" />
  187.                         <forward name="edit-success" path="/product/edit_leave_word.jsp" redirect="false" />
  188.                         <forward name="delete-success" path="/product/leaveWordF.do?method=list" redirect="true" />
  189.                         <forward name="delete-failure" path="/product/error.jsp" redirect="false" />
  190.                         <forward name="list-success" path="/product/list_leave_word.jsp" redirect="false" />
  191.                         <forward name="view-success" path="/product/view_leave_word.jsp" redirect="false" />
  192.                 </action>
  193.         <action path="/product/productNewsF" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" name="productNewsForm" scope="request"><forward name="add-success" path="/product/add_product_news.jsp" redirect="false" /><forward name="edit_success" path="/product/edit_product_news.jsp" redirect="false" /><forward name="delete-success" path="/product/productNewsF.do?method=list" redirect="false" /><forward name="delete-failure" path="/error.jsp" redirect="false" /></action><action path="/product/fileT" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy" name="fileForm" scope="request"><forward name="upload-success" path="/product/list_file.jsp" redirect="true" /></action><action path="/product/fileF" parameter="method" type="com.bupticet.strutsinterceptor.InterceptorActionProxy"><forward name="list-success" path="/product/list_file.jsp" redirect="false" /><forward name="add-success" path="/product/upload_file.jsp" redirect="false" /></action></action-mappings>
  194.         <controller inputForward="true" maxFileSize="2M" nocache="true" />
  195.         <message-resources parameter="com.bupticet.product.web.resources.ProductResources" null="false" />
  196.         <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
  197.                 <set-property property="pathnames" value="/WEB-INF/validate/validator-rules.xml,/WEB-INF/validate/validation.xml" />
  198.                 <set-property property="stopOnFirstError" value="true" />
  199.         </plug-in>
  200.         <plug-in className="com.bupticet.integration.spring2struts.CorrectContextLoaderPlugIn">
  201.                 <set-property property="contextConfigLocation" value="classpath:/config/spring/applicationContext-strutsinterceptor.xml,classpath:/config/spring/applicationContext-view.xml,classpath:/config/spring/applicationContext-business.xml,classpath:/config/spring/applicationContext-persistence.xml" />
  202.         </plug-in>
  203. </struts-config>

复制代码
回复 支持 反对

使用道具 举报

发表于 2005-8-20 01:08:07 | 显示全部楼层
真? good
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表