<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異常編碼

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


    網站導航:
     
    主站蜘蛛池模板: 国产小视频在线观看免费| 国产精品视频免费一区二区| 亚洲日韩涩涩成人午夜私人影院| 亚洲欧洲专线一区| 女人18特级一级毛片免费视频| 亚洲一区动漫卡通在线播放| 黄页网站在线看免费| 亚洲同性男gay网站在线观看| 麻豆国产精品免费视频| 亚洲人成在久久综合网站| 永久免费的网站在线观看| 亚洲成av人无码亚洲成av人| 四虎影视永久免费视频观看| 免费一区二区三区在线视频| 久久久久噜噜噜亚洲熟女综合| 嫩草在线视频www免费观看| 亚洲视频在线不卡| 午夜视频免费观看| 一区二区在线视频免费观看| 亚洲精品无码成人片久久| 1000部禁片黄的免费看| 亚洲av永久无码一区二区三区| 亚洲国产香蕉人人爽成AV片久久 | 精品国产免费观看久久久| 国产99久久亚洲综合精品| 国产AV无码专区亚洲AV漫画| 在线观看的免费网站无遮挡 | 日韩一区二区三区免费播放| 亚洲精品无码久久久影院相关影片| 9420免费高清在线视频| 亚洲日韩精品无码AV海量| 中文字幕亚洲专区| a拍拍男女免费看全片| 国产精品亚洲片在线花蝴蝶| 国产AV无码专区亚洲AVJULIA| 国产成人精品免费视频网页大全 | 毛片基地看看成人免费| 亚洲国产精品午夜电影| 一本久到久久亚洲综合| 久久久久免费精品国产小说| 亚洲精品V天堂中文字幕|