posts - 16, comments - 6, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          Struts2.0 實現自定義異常國際化

          Posted on 2009-11-19 11:50 java-flying 閱讀(796) 評論(2)  編輯  收藏
           1package com.xunjie.game.answer.web.utils;
           2
           3import java.util.List;
           4
           5import com.opensymphony.xwork2.ActionInvocation;
           6import com.opensymphony.xwork2.ActionSupport;
           7import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
           8import com.xunjie.game.answer.common.CommException;
           9
          10public class CommExceptionInterceptor extends AbstractInterceptor {
          11
          12    public String intercept(ActionInvocation invocation) throws Exception {
          13        String result = null;
          14        try {
          15            result = invocation.invoke();
          16        }
           catch (CommException exception) {
          17            
          18            ActionSupport as = (ActionSupport)invocation.getAction();
          19            processBaseException(as, exception);
          20            
          21            List exceptions = exception.getExceptions();
          22            if (exceptions != null && !exceptions.isEmpty()) {
          23                for (int i = 0; i < exceptions.size(); i++{
          24                    CommException subEX = (CommException) exceptions.get(i);
          25                    processBaseException(as, subEX);
          26                }

          27            }

          28            throw exception;
          29        }

          30        return result;
          31    }

          32
          33    private void processBaseException(ActionSupport action, CommException commException) {
          34        String messageKey = commException.getMessageKey();
          35        String[] args = commException.getMessageArgs();
          36        
          37        if (args != null && args.length > 0{
          38            String s = action.getText(messageKey, args);
          39            action.addActionError(s);
          40        }
           else {
          41            String s = action.getText(messageKey);
          42            action.addActionError(s);
          43        }

          44    }

          45}

          46

          評論

          # re: Struts2.0 實現自定義異常國際化[未登錄]  回復  更多評論   

          2011-11-10 21:52 by 111
          可以把這個類給出來不

          # re: Struts2.0 實現自定義異常國際化[未登錄]  回復  更多評論   

          2011-11-10 21:53 by 小楊
          可以將那個基礎的Exception 貼出來不

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


          網站導航:
           
          主站蜘蛛池模板: 汉寿县| 军事| 寿宁县| 当涂县| 马鞍山市| 保德县| 麟游县| 广昌县| 舒兰市| 江永县| 山西省| 镇平县| 易门县| 华宁县| 卢龙县| 曲阳县| 泰州市| 青浦区| 松江区| 苏尼特左旗| 恭城| 特克斯县| 忻州市| 察哈| 宁蒗| 察隅县| 东源县| 珲春市| 呼和浩特市| 青浦区| 贡觉县| 海安县| 瑞丽市| 平阴县| 瓮安县| 吴桥县| 垫江县| 伊通| 新巴尔虎左旗| 彭山县| 甘泉县|