国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

定制一個靈活的struts框架

2019-11-17 06:33:49
字體:
來源:轉載
供稿:網友

用過struts的朋友應該都知道,struts的action類提供的execute方法有四個參數,這是一種非常大范圍的解決方案,而現實中我們的Action類中的方法可能只處理或者只需要個別參數,也許只需要actionform,或者甚至你都不需要,下面的代碼為大家展示如何通過java的反射機制來靈活實現.
-------------
      /*  all code should insert into excute method of actionclass*/
     
      /*  get the type of the current actionclass*/
      Class clazz = this.getClass(  );
     
     
      /*      get all the methods in this actionclass       */
      Method[] methods = clazz.getMethods;
     
      /*      put all the method into hashmap               */
      HashMap methodss = new HashMap(  );
      for(int i=0;i<methods.length;i++){
      methodss.add(methods[i].getname(),methods[i])
      }
     
      /*      get the name of the method you want invokde  */
      String methodsname=request.getparameter("methodsname");
     
     
      /*      choose the method that you want invoke      */
      Class[] para= methodss.get("methodsname").getParameterTypes();
      try {
  if (para.length==1){
     if (para[0].getClass().newInstance() instanceof  ActionForm) {
      
    Object[] argst ={form};
    return (ActionForward) method.invoke( this,  argst);
    
   }
    .................................. 
     
    }
 } catch (InstantiationException e) {
   TODO Auto-generated catch block
  e.PRintStackTrace();
 }


-----------

這樣,開發人員就可以在action中按自己的需要來寫方法了,為將來單體的測試也很有用,究竟四個參數全用的情況是很少的,當然,我現在寫的還有問題,就是方法的名稱不能重復,這是因為目前處理的地方不是很好,希望大家一起討論........



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 北流市| 浏阳市| 龙川县| 岳阳市| 长汀县| 防城港市| 卓资县| 平武县| 蓝田县| 忻城县| 广南县| 邹城市| 连州市| 四川省| 中江县| 吉木萨尔县| 微博| 蛟河市| 宜君县| 鄂伦春自治旗| 富平县| 乾安县| 富裕县| 邵武市| 鄢陵县| 宜宾市| 长沙市| 兰溪市| 金湖县| 集贤县| 若羌县| 锡林郭勒盟| 泰来县| 尼木县| 临澧县| 武功县| 迁西县| 锡林浩特市| 永胜县| 西乡县| 焦作市|