<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 68, comments - 19, trackbacks - 0, articles - 1

    Struts1自動異常處理

    Posted on 2011-02-25 21:05 viery 閱讀(548) 評論(0)  編輯  收藏
    1.異常類

    public class SystemException extends RuntimeException {

     private String key;//得到本地資源文件key
      private Object[] values;
     
      public SystemException() {
       super();
      }

      public SystemException(String message, Throwable arg1) {
       super(message, arg1);
      }

      public SystemException(String message) {
       super(message);
      }

      public SystemException(Throwable message) {
       super(message);
      }

      public SystemException(String key,String message, Throwable arg1) {
       super(message, arg1);
       this.key = key;
      }
      public SystemException(String key,String message) {
        super(message);
        this.key = key;
       }
      public SystemException(String key,Object value) {
       super();
       this.key = key;
       values = new Object[]{value};
      }
     
      public SystemException(String key,Object value1,Object value2) {
       super();
       this.key = key;
       values = new Object[]{value1,value2};
      }
     
      public SystemException(String key,Object[] values) {
       super();
       this.key = key;
       this.values = values;
      }

      public String getKey() {
       return key;
      }

      public Object[] getValues() {
       return values;
      }

     

    }

    2.處理器

    public class SystemExceptionHandler extends ExceptionHandler {

     /**
      * 處理SystenException異常
      */
     @Override
      public ActionForward execute(Exception ex, ExceptionConfig ae,
          ActionMapping mapping, ActionForm formInstance,
          HttpServletRequest request, HttpServletResponse response)
          throws ServletException {
        
               ActionForward forward = null;
               ActionMessage error = null;
               String property = null; 
        
               if (ae.getPath() != null) {//配置文件中的path
                   forward = new ActionForward(ae.getPath());
               } else {
                   forward = mapping.getInputForward();//如果沒有找到path,轉到input配置的路徑
               } 
        
               this.logException(ex);
              
         //處理自定義的異常類SystemException
         if(ex instanceof SystemException){
          SystemException se = (SystemException)ex;
          //如果只有message,而沒有key
          if(se.getKey() == null){
           error = new ActionMessage(ae.getKey(), ex.getMessage());
           property = ae.getKey();
          }else{ //SystemException中有key值
           error = new ActionMessage(se.getKey(),se.getValues());
           property = se.getKey();
          }
                request.setAttribute(Globals.EXCEPTION_KEY, ex);
                this.storeException(request, property, error, forward, ae.getScope());
               
                return forward;
         }
        
         return super.execute(ex, ae, mapping, formInstance, request, response);

     }

    }

    3.struts配置
     <global-exceptions>
      <exception key="errors.detail"
           type="com.v.oa.common.SystemException"
           path="/common/exception.jsp"
           scope="request"
           handler="com.v.oa.common.SystemExceptionHandler">
          
      </exception>
     </global-exceptions>
    4.<html:errors/>
    5.國際化資源文件 可以用0001編碼 類似oracle異常編碼

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     
    主站蜘蛛池模板: gogo免费在线观看| 国产亚洲精品成人久久网站| 中国在线观看免费的www| 日韩午夜免费视频| 亚洲人成网亚洲欧洲无码| 四虎在线免费视频| 亚洲AV无码成人精品区日韩| 91成年人免费视频| 2020年亚洲天天爽天天噜| 成人毛片免费在线观看| 亚洲第一se情网站| 免费成人午夜视频| 中文字幕免费播放| 亚洲ⅴ国产v天堂a无码二区| 99久久久国产精品免费牛牛| 亚洲熟妇av一区二区三区下载| 91精品导航在线网址免费| 亚洲xxxxxx| 免费在线视频一区| 波多野结衣免费一区视频| 亚洲永久中文字幕在线| 毛片在线看免费版| 男人免费视频一区二区在线观看| 国产亚洲精品无码成人| 黄在线观看www免费看| 国产精品国产亚洲区艳妇糸列短篇| 亚洲精品久久久www | 久久不见久久见免费影院| MM1313亚洲精品无码久久| 亚洲中文字幕无码一区二区三区| 亚洲一区免费观看| 亚洲欧美日韩中文字幕在线一区| AV在线播放日韩亚洲欧| **毛片免费观看久久精品| 久久久久亚洲AV无码去区首| 亚洲国产精品特色大片观看完整版| 久久久久久久91精品免费观看| 无码天堂亚洲国产AV| 久久青草亚洲AV无码麻豆| 国内一级一级毛片a免费| japanese色国产在线看免费|