posts - 16, comments - 6, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Struts2.0 实现自定义异常国际化

Posted on 2009-11-19 11:50 java-flying 阅读(779) 评论(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 贴出来不

只有注册用户登录后才能发表评论。


网站导航: