LinuxSir.cn,穿越时空的Linuxsir!

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

自己做了个支持DispatchAction的struts拦截器

[复制链接]
发表于 2005-4-1 21:34:01 | 显示全部楼层 |阅读模式

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

  6. import java.io.IOException;

  7. import javax.servlet.ServletException;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;

  10. import org.apache.struts.action.ActionForm;
  11. import org.apache.struts.action.ActionForward;
  12. import org.apache.struts.action.ActionMapping;

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

  40.         /**
  41.          *  Called after an action is executed
  42.          *
  43.          *@param  mapping               The action mapping
  44.          *@param  form                  The action form
  45.          *@param  request               The request object
  46.          *@param  response              The response object
  47.          *@exception  IOException       If something goes wrong
  48.          *@exception  ServletException  If something goes wrong
  49.          */
  50.         public void afterAction(ActionMapping mapping,
  51.                         ActionForm form, HttpServletRequest request,
  52.                         HttpServletResponse response)
  53.                 throws IOException, ServletException;
  54.                
  55.         /**
  56.          *  Called when exception is throwed
  57.          *
  58.          */
  59.         public ActionForward throwsAction(ActionMapping mapping,
  60.         ActionForm form, HttpServletRequest request,
  61.         HttpServletResponse response,Exception e)
  62.                 throws Exception;       
  63. }

复制代码
 楼主| 发表于 2005-4-1 21:48:07 | 显示全部楼层

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

  6. import java.util.List;

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

  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.springframework.web.struts.DelegatingActionProxy;

  14. /**
  15. * <p>Title: InterceptorActionProxy</p>
  16. *
  17. * <p>Description: 拦截器代理Action类</p>
  18. *
  19. * <p>Copyright: Copyright (c)北京邮电大学网络教育技术研究所[www.buticet.com] 2005</p>
  20. *
  21. * <p>Company: 北京邮电大学网络教育技术研究所[www.buticet.com] </p>
  22. *
  23. * @author LJ-silver  E-mail:LJ-silver@163.com
  24. * @version 1.0
  25. */
  26. public class InterceptorActionProxy extends DelegatingActionProxy {
  27.        
  28.         static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(InterceptorActionProxy.class);
  29.         /**
  30.          * Pass the execute call on to the Spring-managed delegate Action.
  31.          * @see #getDelegateAction
  32.          */
  33.         public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
  34.                                                                                                                          HttpServletResponse response) throws Exception {
  35.                 Action delegateAction = getDelegateAction(mapping);
  36.                 ActionForward forward = null;
  37.                 List interceptorList = InterceptorConfig.getInterceptorList(request);
  38.                 int size = interceptorList.size();
  39.                 if(size > 0){
  40.                         ActionInterceptor[] interceptorArray = new ActionInterceptor[size];
  41.                         for(int i = 0;i<size;i++){
  42.                                 interceptorArray[i] = (ActionInterceptor)Class.forName((String)interceptorList.get(i)).newInstance();
  43.                         }
  44.                         try{
  45.                                 for(int i = 0;i<size;i++){
  46.                                         forward = interceptorArray[i].beforeAction(mapping, form, request, response);
  47.                                         if(forward!=null){
  48.                                                 return forward;                                       
  49.                                         }
  50.                                 }                                               
  51.                                 forward = delegateAction.execute(mapping, form, request, response);
  52.                                 for(int i = 0;i<size;i++){
  53.                                         interceptorArray[i].afterAction(mapping, form, request, response);
  54.                                 }
  55.                        
  56.                         }catch(Exception e){
  57.                                 e.printStackTrace();
  58.                                 logger.error("In execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response), Exception Occured ! Info :" + e.getLocalizedMessage());
  59.                                 for(int i = 0;i<size;i++){
  60.                                         forward = interceptorArray[i].throwsAction(mapping, form, request, response,e);
  61.                                         if(forward!=null){
  62.                                                 return forward;
  63.                                         }
  64.                                 }
  65.                         }
  66.                 }else{
  67.                         forward = delegateAction.execute(mapping, form, request, response);
  68.                 }
  69.                 return forward;
  70.         }       

  71. }

复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-1 21:49:17 | 显示全部楼层

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

  6. import java.io.InputStream;
  7. import java.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.Iterator;
  10. import java.util.List;
  11. import java.util.Map;

  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.xml.parsers.DocumentBuilder;
  14. import javax.xml.parsers.DocumentBuilderFactory;

  15. import org.apache.struts.config.ActionConfig;
  16. import org.w3c.dom.Document;
  17. import org.w3c.dom.Element;
  18. import org.w3c.dom.NodeList;
  19. import org.xml.sax.SAXException;

  20. /**
  21. * <p>Title: InterceptorConfig</p>
  22. *
  23. * <p>Description: 配置文件读取类</p>
  24. *
  25. * <p>Copyright: Copyright (c)北京邮电大学网络教育技术研究所[[url]www.buticet.com][/url] 2005</p>
  26. *
  27. * <p>Company: 北京邮电大学网络教育技术研究所[[url]www.buticet.com][/url] </p>
  28. *
  29. * @author LJ-silver E-mail:LJ-silver@163.com
  30. * @version 1.0
  31. */
  32. public class InterceptorConfig {
  33.         private static HashMap config;
  34.        
  35.         private final static String filePathName = "/struts-interceptor.xml";  
  36.        
  37.         static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(InterceptorConfig.class);
  38.        
  39.         public static void init(){
  40.                 if(config==null){
  41.                         initResource();
  42.                 }
  43.         }
  44.                
  45.         private static void initResource(){
  46.                 Document document = null;
  47.                 try{
  48.                         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  49.                         DocumentBuilder db = dbf.newDocumentBuilder();
  50.                         InputStream is = InterceptorConfig.class.getResourceAsStream(filePathName);
  51.                         document = db.parse(is);
  52.                         Element root = document.getDocumentElement();
  53.                         NodeList interceptors = root.getElementsByTagName("interceptor-definition");
  54.                         Map map = new HashMap();
  55.                         for(int i = 0;i<interceptors.getLength();i++){
  56.                                 Element interceptor = (Element) interceptors.item(i);
  57.                                 if(map.containsKey(interceptor.getAttribute("name"))){
  58.                                         logger.error("In initResource(), Exception Occured !Info :不能重复配置interceptor-definition元素:"+interceptor.getAttribute("name"));
  59.                                 }else{
  60.                                         map.put(interceptor.getAttribute("name"),interceptor.getAttribute("type"));
  61.                                 }
  62.                         }
  63.                         NodeList actions = document.getElementsByTagName("action");
  64.                         config = new HashMap();
  65.                         for(int i = 0;i<actions.getLength();i++){
  66.                                 Element action = (Element) actions.item(i);
  67.                                 String path = action.getAttribute("path");
  68.                                 NodeList methods = action.getElementsByTagName("method");
  69.                                 Map temp = new HashMap();
  70.                                 for(int j = 0;j<methods.getLength();j++){
  71.                                         Element method = (Element) methods.item(j);
  72.                                         String name = method.getAttribute("name");
  73.                                         List actionInterceptorList = new ArrayList();
  74.                                         NodeList actionInterceptors = method.getElementsByTagName("interceptor");
  75.                                         for(int k = 0;k<actionInterceptors.getLength();k++){
  76.                                                 Element actionInterceptor = (Element) actionInterceptors.item(k);
  77.                                                 String interceptorName = actionInterceptor.getAttribute("name");
  78.                                                 if(map.containsKey(interceptorName)){
  79.                                                         actionInterceptorList.add(map.get(interceptorName));
  80.                                                 }else{
  81.                                                         logger.error("In initResource(), Exception Occured !Info :没有"+interceptorName+"对应的interceptor-definition元素!" );
  82.                                                 }

  83.                                         }
  84.                                         String[] allMethods = name.split(",");
  85.                                         for(int m = 0;m<allMethods.length;m++){
  86.                                                 if(temp.containsKey(allMethods[m])){
  87.                                                         logger.error("In initResource(), Exception Occured !Info :不能重复配置method元素:"+allMethods[m] );
  88.                                                 }else{
  89.                                                         temp.put(allMethods[m],actionInterceptorList);
  90.                                                 }
  91.                                         }
  92.                                 }
  93.                                 if(config.containsKey(path)){
  94.                                         logger.error("In initResource(), Exception Occured !Info :不能重复配置path元素:"+path );
  95.                                 }else{
  96.                                         config.put(path,temp);
  97.                                 }
  98.                         }               
  99.                 }catch(IllegalArgumentException  e){
  100.                         logger.error("In initResource(), Exception Occured ! 找不到文件/WEB-INF/classes/struts-interceptor.xml!,Info :" + e.getLocalizedMessage());
  101.                         e.printStackTrace();
  102.                 }catch(SAXException e){
  103.                         logger.error("In initResource(), Exception Occured ! XML文件/WEB-INF/classes/struts-interceptor.xml语法错误!,Info :" + e.getLocalizedMessage());
  104.                         e.printStackTrace();
  105.                 }catch(Exception e){
  106.                         logger.error("In initResource(), Exception Occured !Info :" + e.getLocalizedMessage());
  107.                         e.printStackTrace();
  108.                 }
  109.         }
  110.        
  111.        
  112.         public static List getInterceptorList(String path,String method){
  113.                 init();
  114.                 List list = new ArrayList();
  115.                 if(config.containsKey(path)){
  116.                         HashMap map = (HashMap)config.get(path);
  117.                         if(map.containsKey(method)){
  118.                                 list = (ArrayList)map.get(method);
  119.                         }
  120.                 }
  121.                 return list;
  122.         }
  123.        
  124.         public static List getInterceptorList(HttpServletRequest request){
  125.                 ActionConfig actionConfig = (ActionConfig)request.getAttribute("org.apache.struts.action.mapping.instance");
  126.                 String path = actionConfig.getPath();
  127.                 String method = null;
  128.                 String parameter = actionConfig.getParameter();
  129.                 if(parameter!=null&&!"".equals(actionConfig.getParameter())){
  130.                         method = request.getParameter(parameter);
  131.                 }
  132.                 if(method==null||"".equals(method)){
  133.                         method = "execute";
  134.                 }
  135.                 return getInterceptorList(path,method);
  136.         }
  137.        
  138.         public static void test(){
  139.                 init();
  140.                 for(Iterator it = config.keySet().iterator();it.hasNext();){
  141.                         String key = (String)it.next();
  142.                         System.out.println(key);
  143.                         Map map = (HashMap)config.get(key);
  144.                         for(Iterator ite = map.keySet().iterator();ite.hasNext();){
  145.                                 String key2 = (String)ite.next();
  146.                                 System.out.println("------------------------"+key2);
  147.                                 List list = (ArrayList)map.get(key2);
  148.                                 for(Iterator iter = list.iterator();iter.hasNext();){
  149.                                         System.out.println("------------------------"+"     "+"------------------------"+(String)iter.next());
  150.                                 }
  151.                         }
  152.                 }
  153.                
  154.        
  155.         }
  156. }

复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-1 21:50:07 | 显示全部楼层

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

  6. import java.io.IOException;

  7. import javax.servlet.ServletException;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import javax.servlet.http.HttpSession;

  11. import org.apache.struts.Globals;
  12. import org.apache.struts.action.ActionForm;
  13. import org.apache.struts.action.ActionForward;
  14. import org.apache.struts.action.ActionMapping;
  15. import org.apache.struts.action.ActionMessage;
  16. import org.apache.struts.action.ActionMessages;

  17. import com.bupticet.strutsinterceptor.ActionInterceptor;

  18. /**
  19. * <p>Title: </p>
  20. *
  21. * <p>Description: </p>
  22. *
  23. * <p>Copyright: Copyright (c)北京邮电大学网络教育技术研究所[[url]www.buticet.com][/url] 2005</p>
  24. *
  25. * <p>Company: 北京邮电大学网络教育技术研究所[[url]www.buticet.com][/url] </p>
  26. *
  27. * @author LJ-silver
  28. * @version 1.0
  29. */
  30. public class LoginPermissionInterceptor implements ActionInterceptor {

  31.         /*
  32.          * @see com.bupticet.strusinterceptor.ActionInterceptor#beforeAction(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
  33.          */
  34.         public ActionForward beforeAction(
  35.                 ActionMapping mapping,
  36.                 ActionForm form,
  37.                 HttpServletRequest request,
  38.                 HttpServletResponse response)
  39.                 throws IOException, ServletException {
  40.                 HttpSession session = request.getSession();
  41.                 if(session.getAttribute(com.bupticet.example.Constants.USER_ATTRIBUTE)!=null){
  42.                         ActionMessages errors = new ActionMessages();
  43.                         errors.add(ActionMessages.GLOBAL_MESSAGE ,new ActionMessage("error.login.alreadylogin"));
  44.                         request.setAttribute(Globals.ERROR_KEY, errors);
  45.                         return mapping.findForward("failure");
  46.                 }
  47.                 return null;
  48.         }

  49.         /*
  50.          * @see com.bupticet.strusinterceptor.ActionInterceptor#afterAction(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
  51.          */
  52.         public void afterAction(
  53.                 ActionMapping mapping,
  54.                 ActionForm form,
  55.                 HttpServletRequest request,
  56.                 HttpServletResponse response)
  57.                 throws IOException, ServletException {

  58.         }

  59.         /*
  60.          * @see com.bupticet.strusinterceptor.ActionInterceptor#throwsAction(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Exception)
  61.          */
  62.         public ActionForward throwsAction(
  63.                 ActionMapping mapping,
  64.                 ActionForm form,
  65.                 HttpServletRequest request,
  66.                 HttpServletResponse response,
  67.                 Exception e)
  68.                 throws Exception {
  69.                 return null;
  70.         }

  71. }

复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-1 21:52:38 | 显示全部楼层

struts-interceptor.xml


  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- interceptor in SSH(Struts+Spring+Hibernate) created by LJ-silver-->
  3. <struts-interceptor>

  4.         <interceptor-definition name="login" type="com.bupticet.example.struts.interceptor.LoginPermissionInterceptor"/>


  5.         <action path="/example/loginT">
  6.                 <method name="login">
  7.                         <interceptor name="login"/>
  8.                 </method>
  9.         </action>

  10. </struts-interceptor>
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-1 21:55:12 | 显示全部楼层

spring配置文件applicationContext.xml片断

我在这里面也弄了个拦截器,不过拦截DispatchAction里面的自定义方法不太好用。


  1.     <!-- define a transaction manager -->
  2.     <bean id="transactionManager"
  3.         class="org.springframework.orm.hibernate.HibernateTransactionManager"
  4.         lazy-init="true">
  5.         <property name="sessionFactory">
  6.             <ref bean="hibernateSessionFactory"/>
  7.         </property>
  8.     </bean>

  9.         <!-- define userDao -->
  10.     <bean id="userDao" class="com.bupticet.example.dao.impl.UserDaoImpl" lazy-init="true">
  11.         <property name="sessionFactory">
  12.             <ref bean="hibernateSessionFactory"/>
  13.         </property>
  14.     </bean>

  15.         <bean id="userDaoProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  16.                 <property name="transactionManager">
  17.                         <ref bean="transactionManager" />
  18.                 </property>
  19.                 <property name="target">
  20.                         <ref local="userDao" />
  21.                 </property>
  22.                 <property name="transactionAttributes">
  23.                         <props>
  24.                                 <prop key="saveOrUpdate*">PROPAGATION_REQUIRED</prop>
  25.                                 <prop key="delete*">PROPAGATION_REQUIRED</prop>
  26.                                 <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
  27.                                 <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
  28.                         </props>
  29.                 </property>
  30.         </bean>

  31.         <!-- define userDao -->
  32.      <bean id="articleDao" class="com.bupticet.example.dao.impl.ArticleDaoImpl" lazy-init="true">
  33.         <property name="sessionFactory">
  34.             <ref bean="hibernateSessionFactory"/>
  35.         </property>
  36.     </bean>   

  37.         <bean id="articleDaoProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  38.                 <property name="transactionManager">
  39.                         <ref bean="transactionManager" />
  40.                 </property>
  41.                 <property name="target">
  42.                         <ref local="articleDao" />
  43.                 </property>
  44.                 <property name="transactionAttributes">
  45.                         <props>
  46.                                 <prop key="login*">PROPAGATION_REQUIRED</prop>
  47.                                 <prop key="saveOrUpdate*">PROPAGATION_REQUIRED</prop>
  48.                                 <prop key="delete*">PROPAGATION_REQUIRED</prop>
  49.                                 <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
  50.                                 <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
  51.                                 <prop key="check*">PROPAGATION_REQUIRED,readOnly</prop>
  52.                         </props>
  53.                 </property>
  54.         </bean>

  55.         <!-- define LoginAction use aop  -->
  56.         <bean name="/example/loginT" class="org.springframework.aop.framework.ProxyFactoryBean">
  57.                         <!--use dynamic aop or cglib
  58.                 <property name="proxyInterfaces">
  59.                         <value>com.bupticet.example.struts.ILoginTAction</value>
  60.                 </property>
  61.                         -->
  62.                 <property name="proxyTargetClass">
  63.                         <value>true</value>
  64.                 </property>

  65.                 <property name="target">
  66.                         <ref local="loginT" />
  67.                 </property>
  68.                 <property name="interceptorNames">
  69.                         <value>LoginTPointcutAdvisor</value>
  70.                 </property>
  71.         </bean>

  72.         <bean id="LoginTPointcutAdvisor"
  73.                 class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
  74.                 <property name="advice">
  75.                         <ref local="LoginTInterceptor" />
  76.                 </property>
  77.                 <property name="patterns">
  78.                         <list>
  79.                                 <value>.*</value>
  80.                         </list>
  81.                 </property>
  82.         </bean>

  83.         <bean id="LoginTInterceptor" class="com.bupticet.example.strutsaop.LoginTInterceptor"/>
  84.         
  85.         <bean id="loginT" class="com.bupticet.example.struts.LoginTAction" singleton="false">
  86.                 <property name="userDao">
  87.                         <ref bean="userDaoProxy" />
  88.                 </property>
  89.         </bean>

  90.         <!-- define UserAction use aop  -->
  91.         <bean name="/example/userT" class="com.bupticet.example.struts.UserTAction" singleton="false">
  92.                 <property name="userDao">
  93.                         <ref bean="userDaoProxy" />
  94.                 </property>
  95.         </bean>
  96.         <bean name="/example/userF" class="com.bupticet.example.struts.UserFAction" singleton="false">
  97.                 <property name="userDao">
  98.                         <ref bean="userDaoProxy" />
  99.                 </property>
  100.         </bean>
  101.         <bean name="/example/articleT" class="com.bupticet.example.struts.ArticleTAction" singleton="false">
  102.                 <property name="articleDao">
  103.                         <ref bean="articleDaoProxy" />
  104.                 </property>
  105.         </bean>
  106.         <bean name="/example/articleF" class="com.bupticet.example.struts.ArticleFAction" singleton="false">
  107.                 <property name="articleDao">
  108.                         <ref bean="articleDaoProxy" />
  109.                 </property>
  110.         </bean>

复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-1 21:56:35 | 显示全部楼层

  1. /*
  2. * 创建日期 2005-3-30
  3. *
  4. */
  5. package com.bupticet.example.strutsaop;

  6. import java.io.Serializable;
  7. import java.lang.reflect.Method;
  8. import java.util.Enumeration;

  9. import javax.servlet.http.HttpServletRequest;

  10. import org.aopalliance.intercept.MethodInterceptor;
  11. import org.aopalliance.intercept.MethodInvocation;
  12. import org.apache.struts.config.ActionConfig;

  13. /**
  14. * <p>Title: </p>
  15. *
  16. * <p>Description: </p>
  17. *
  18. * <p>Copyright: Copyright (c)北京邮电大学网络教育技术研究所[[url]www.buticet.com][/url] 2005</p>
  19. *
  20. * <p>Company: 北京邮电大学网络教育技术研究所[[url]www.buticet.com][/url] </p>
  21. *
  22. * @author LJ-silver
  23. * @version 1.0
  24. */
  25. public class LoginTInterceptor implements MethodInterceptor, Serializable {
  26.        
  27.         static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(LoginTInterceptor.class);

  28.         /*
  29.          * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
  30.          */
  31.         public Object invoke(MethodInvocation arg0) throws Throwable {
  32.                 logger.info("====================before run======================");
  33.                 System.out.println("====================before run======================"+arg0.getMethod().getName());
  34.                 Method method = arg0.getMethod();
  35.                 Object[] args = arg0.getArguments();
  36.                 if(args[2]instanceof HttpServletRequest){
  37.                         System.out.println("HttpServletRequest");
  38.                         System.out.println("=====================================================================");
  39.                         HttpServletRequest request = (HttpServletRequest)args[2];
  40.                         for(Enumeration e = request.getAttributeNames();e.hasMoreElements();){
  41.                                 Object o = e.nextElement();
  42.                                 System.out.println((String)o+"::::"+request.getAttribute((String)o));
  43.                         }
  44.                         System.out.println("=====================================================================");
  45.                         ActionConfig actionConfig = (ActionConfig)request.getAttribute("org.apache.struts.action.mapping.instance");
  46.                         String parameter = actionConfig.getParameter();
  47.                         if(null!=request.getParameter(parameter)){
  48.                                 String methodName = (String)request.getParameter("method");
  49.                                 if("login".equals(methodName)){
  50.                                         System.out.println("before run action:login");
  51.                                 }
  52.                         }
  53.                 }
  54.                 Object result = arg0.proceed();
  55.                 logger.info("====================after run======================");
  56.                 System.out.println("====================after run======================");
  57.                 return result;
  58.         }

  59. }

复制代码
回复 支持 反对

使用道具 举报

发表于 2005-4-3 22:42:45 | 显示全部楼层
现在是不是很少人用struts阿? 感觉struts的标签和配置都太繁琐了
回复 支持 反对

使用道具 举报

发表于 2005-4-4 08:57:50 | 显示全部楼层
Post by linzchang
现在是不是很少人用struts阿? 感觉struts的标签和配置都太繁琐了

按照国外的调查,ava web 开发用人70%都要求会struts
回复 支持 反对

使用道具 举报

发表于 2005-4-4 23:26:33 | 显示全部楼层
Post by hantsy
按照国外的调查,ava web 开发用人70%都要求会struts

那么说struts还是不错的, 努力学习中:)
回复 支持 反对

使用道具 举报

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

本版积分规则

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