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

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

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

    posts - 431,  comments - 344,  trackbacks - 0

    開發interceptor的時候,了解action已經執行完畢而result還沒有開始執行的時間點往往很重要的。譬如在異常處理方面就是如此:在action處理的過程中,由于后臺的處理,出現的異常很可能是系統異常;而在result處理的過程中,異常則可能出現在為用戶呈現的頁面的時候,而不是由于系統問題。
    下面給出了ExceptionInterceptor的代碼,該interceptor會在result開始執行之前與之后以不同的方式處理異常。在result開始執行之前,可以改變用于從action配置中查詢result的返回碼,而在webwork應用程序中,使用Action.ERROR是一個常用的實踐技巧:將Action.ERROR映射至向用戶提示錯誤的頁面。所以,需要捕獲異常并返回Action.ERROR。在result開始執行之后,來自interceptor的返回碼就不再那樣重要了,但是仍然可以獲得由beforeResult()方法回傳給result code,并且可以返回它。在以下離子中需要注意的一點是:由于interceptor必須是無狀態的,因此它為每一個ActionInvocation創建一個新的ExceptionHandler,可以保存該ActionInvocation的狀態。
    ExceptionInterceptor:在result前后以不同的方式處理異常
    /**
     * @filename ExceptionInterceptor.java
     * @author Rain_zhou
     * @version ExceptionInterceptor,下午01:05:50
     */
    package com.founder.study.forum.interceptor;

    import com.opensymphony.xwork.ActionInvocation;
    import com.opensymphony.xwork.interceptor.Interceptor;

    /**
     * @author Rain_zhou
     *
     */
    public class ExceptionInterceptor implements Interceptor {

     /* (non-Javadoc)
      * @see com.opensymphony.xwork.interceptor.Interceptor#destroy()
      */
     public void destroy() {
      // TODO Auto-generated method stub

     }

     /* (non-Javadoc)
      * @see com.opensymphony.xwork.interceptor.Interceptor#init()
      */
     public void init() {
      // TODO Auto-generated method stub

     }

     /* (non-Javadoc)
      * @see com.opensymphony.xwork.interceptor.Interceptor#intercept(com.opensymphony.xwork.ActionInvocation)
      */
     public String intercept(ActionInvocation arg0) throws Exception {
      // TODO Auto-generated method stub
      ExceptionHandler handler=new ExceptionHandler(arg0);
      return handler.invoke();
     }

    }



    /**
     * @filename ExceptionHandler.java
     * @author Rain_zhou
     * @version ExceptionHandler,下午01:07:04
     */
    package com.founder.study.forum.interceptor;

    import com.founder.study.forum.helper.NoLimitException;
    import com.opensymphony.xwork.Action;
    import com.opensymphony.xwork.ActionInvocation;
    import com.opensymphony.xwork.interceptor.PreResultListener;

    /**
     * @author Rain_zhou
     *
     */
    public class ExceptionHandler implements PreResultListener {

     private ActionInvocation invocation;
     private boolean beforeResult=true;
     private String result=Action.ERROR;
     
     public ExceptionHandler(ActionInvocation invocation){
      this.invocation=invocation;
      invocation.addPreResultListener(this);
     }
     
     String invoke(){
      try{
       result=invocation.invoke();
      }catch(Exception e){
       if(beforeResult){
        return Action.ERROR;
       }else{
        return result;
       }
      }
      return result;
     }
     /* (non-Javadoc)
      * @see com.opensymphony.xwork.interceptor.PreResultListener#beforeResult(com.opensymphony.xwork.ActionInvocation, Java.lang.String)
      */
     public void beforeResult(ActionInvocation arg0, String arg1) {
      // TODO Auto-generated method stub

      beforeResult=false;
      result=arg1;
     }

    }

    posted on 2006-12-25 14:30 周銳 閱讀(2079) 評論(0)  編輯  收藏 所屬分類: Webwork
    主站蜘蛛池模板: 国产永久免费高清在线| 中国一级毛片视频免费看| 久久成人国产精品免费软件| 亚洲精品无码不卡在线播放HE| 日日狠狠久久偷偷色综合免费 | 亚洲天堂视频在线观看| 亚洲综合久久1区2区3区 | j8又粗又长又硬又爽免费视频| 久艹视频在线免费观看| 久久久久亚洲精品成人网小说 | 成年性生交大片免费看| 亚洲av无码乱码在线观看野外| 色欲aⅴ亚洲情无码AV| 国产福利免费观看| 青青草国产免费国产是公开| 亚洲色婷婷综合开心网| 国产午夜亚洲精品| 久久国产色AV免费看| 亚洲国产精品综合久久2007| 免费不卡视频一卡二卡| 亚洲国产精品精华液| 7m凹凸精品分类大全免费| 亚洲国产美女在线观看| 成人免费毛片视频| 美女视频黄视大全视频免费的| 久久亚洲高清综合| 香港a毛片免费观看| 国产午夜亚洲精品理论片不卡 | 国产91精品一区二区麻豆亚洲 | 亚洲色大成WWW亚洲女子| 免费人成在线观看网站| 亚洲女人18毛片水真多| 国产成人免费网站在线观看| 一个人看的www视频免费在线观看| 亚洲AV无码成人精品区蜜桃| 国产成在线观看免费视频| 免费国产黄网站在线观看动图| 亚洲AV一宅男色影视| 成人免费毛片视频| 精品四虎免费观看国产高清午夜| 亚洲AV无码一区二区三区在线|