posts - 16, comments - 6, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
           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 實現(xiàn)自定義異常國際化[未登錄]  回復(fù)  更多評論   

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

          # re: Struts2.0 實現(xiàn)自定義異常國際化[未登錄]  回復(fù)  更多評論   

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

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 曲麻莱县| 道真| 容城县| 神木县| 新乡市| 无极县| 肥东县| 太康县| 子洲县| 城口县| 大新县| 祁连县| 特克斯县| 鄂托克前旗| 交口县| 会东县| 垦利县| 郧西县| 姜堰市| 伊宁市| 高陵县| 绥宁县| 滁州市| 施秉县| 江达县| 图们市| 高台县| 宁乡县| 承德市| 桂东县| 麦盖提县| 无棣县| 册亨县| 肇源县| 望城县| 通山县| 济源市| 瑞昌市| 荣成市| 资中县| 湖北省|