<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 閱讀(552) 評論(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異常編碼

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


    網站導航:
     
    主站蜘蛛池模板: 男女作爱免费网站| 亚洲欧洲精品视频在线观看| 亚洲精品久久无码av片俺去也| 久久国产免费一区| 亚洲国产精品一区二区久久| 亚洲精品线路一在线观看| 亚洲国产成人久久精品软件 | v片免费在线观看| 国产大片免费观看中文字幕| 在线观看亚洲精品福利片| 免费无遮挡无码视频在线观看| gogo全球高清大胆亚洲| 国产精品亚洲一区二区三区| 最近中文字幕国语免费完整| 亚洲一区二区电影| eeuss影院免费直达入口| 亚洲人成网站18禁止一区| 久香草视频在线观看免费| 亚洲日本在线观看视频| 你好老叔电影观看免费| 亚洲国产成人久久综合区| 亚洲国产精品网站在线播放 | 7723日本高清完整版免费| 亚洲一区二区三区久久久久| 成年美女黄网站18禁免费| 青青草原精品国产亚洲av| 成人浮力影院免费看| 亚洲精品无码久久久久APP | 亚洲成AV人片一区二区密柚| 久久一区二区三区免费播放 | 国产jizzjizz视频全部免费| 亚洲男女性高爱潮网站| 欧美男同gv免费网站观看| 亚洲a∨无码男人的天堂| 香蕉高清免费永久在线视频| 亚洲日本国产综合高清| 国产又黄又爽又猛免费app| 国产亚洲精品仙踪林在线播放| 亚洲色无码专区在线观看| 日本三级在线观看免费| 亚洲一区二区三区深夜天堂|