posts - 2,  comments - 5,  trackbacks - 0
webwork提供了异常的统一拦截机制,只需要在xwork.xml中写如下代码
<interceptor name="exception" class="com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor"/>
             
<global-results>
   
<result name="myDaoExceptionPage" type="dispatcher">
    
<param name="location">/WEB-INF/vm/common/wafExceptionPage.jsp</param>
   
</result>
   
<result name="myServiceExceptionPage" type="dispatcher">
    
<param name="location">/WEB-INF/vm/common/wafExceptionPage.jsp</param>
   
</result>
   
<result name="myActionExceptionPage" type="dispatcher">
    
<param name="location">/WEB-INF/vm/common/wafExceptionPage.jsp</param>
   
</result>
   
<result name="myExceptionPage" type="dispatcher">
    
<param name="location">/WEB-INF/vm/common/wafExceptionPage.jsp</param>
   
</result>
   
<result name="exceptionPage" type="dispatcher">
    
<param name="location">/WEB-INF/vm/common/exceptionPage.jsp</param>
  
  </global-results>
  
  
<global-exception-mappings>
     
<exception-mapping name="exceptionPage" exception="java.lang.Exception" result="exceptionPage"/>
   
<exception-mapping name="exceptionPage" exception="net.jite.waf.persistent.exception.MyException" result="myExceptionPage"/>
   
<exception-mapping name="exceptionPage" exception="net.jite.waf.persistent.exception.MyDaoException" result="myDaoExceptionPage"/>
   
<exception-mapping name="exceptionPage" exception="net.jite.waf.persistent.exception.MyServiceException" result="myServiceExceptionPage"/>
   
<exception-mapping name="exceptionPage" exception="net.jite.waf.persistent.exception.MyActionException" result="myActionExceptionPage"/>
  
</global-exception-mappings>
其中有自己定义的相关异常类,以及返回界面,返回界面代码如下:
<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="com.opensymphony.xwork.util.OgnlValueStack"%>
<%@ page import="com.opensymphony.xwork.ActionContext"%>
<%@ page import="com.opensymphony.xwork.interceptor.ExceptionHolder"%>
<%@ page import="net.WAFException"%>
<%@ page import="net.dao.MyDaoException"%>
<%@ page import="net.service.MyServiceException"%>
<%@ page import="netaction.MyActionException"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Exception!</title>
</head>

<body>
<% 
    OgnlValueStack s 
= ActionContext.getContext().getValueStack(); 
    ExceptionHolder e;
    String s1 
= new String("");;
    String name 
= new String("");
    
for(int i = s.size();i>0;i--){
        Object obj 
= s.pop();
        
if(obj instanceof ExceptionHolder){
            e 
= (ExceptionHolder)obj;
            Object o 
= e.getException();
            
if(o instanceof MyException){
                MyException we 
= (MyException)o;
                name 
= we.getExceptionName();
            }
else if(o instanceof MyDaoException){
                MyDaoException we 
= (MyDaoException)o;
                name 
= we.getExceptionName();
            }

            
else if(o instanceof MyServiceException){
                MyServiceException we 
= (MyServiceException)o;
                name 
= we.getExceptionName();
            }

            
else if(o instanceof MyActionException){
                MyActionException we 
= (MyActionException)o;
                name 
= we.getExceptionName();
            }

            s1 
=e.getExceptionStack();
            
break;
        }

    }
     
%>
<table width="400" align="center" valign="middle" border="1" cellspacing="2" cellpadding="2">
<tr><td bgcolor="blue" align="center" height="30" style="font-size:9pt;">
    
<font color="white"><%=name%></font>
</td></tr>
<tr><td>
<H2>错误详细信息:</H2>
<%=s1%><br>
</td>
</tr>
<tr><td align="center">
<input type=button name=return value=返回 onclick="javascript:history.go(-1);">
</td></tr>
</table>
</body>
</html>
posted on 2006-05-23 13:02 火焰男 阅读(1065) 评论(1)  编辑  收藏

FeedBack:
# re: webwork统一处理异常
2008-08-29 10:54 | hnbczr
getValueStack()这个方法是什么意思?  回复  更多评论
  

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


网站导航:
 
<2008年8月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(2)

随笔档案(2)

文章档案(1)

相册

其他人的blog

最新随笔

搜索

  •  

积分与排名

  • 积分 - 7085
  • 排名 - 2724

最新评论

  • 1. re: webwork统一处理异常
  • getValueStack()这个方法是什么意思?
  • --hnbczr
  • 2. re: 用JS生成WORD
  • 数值变成0,0.还有保存的地址要改改。。我估计应该是不是可以不保存的呢!
  • --绗绗
  • 3. re: 用JS生成WORD
  • 谢谢!真的是不知道怎么说谢谢,我研究这个问题好久了,也找了好久答案,身边的人也没有一个告诉我的,我又真的很需要这个答案,所以无敌感谢。估计没机会实际的感谢勒,预祝工作顺利!总之感谢~~
  • --绗绗
  • 4. re: 用JS生成WORD
  • 好象有错误啊
  • --freedom_wind
  • 5. re: 用JS生成WORD
  • 行33
    数值超出范围

    问一下
    var oRange =doc .Range(5,6);
    这句是什么意思?
  • --java爱好者221

阅读排行榜

评论排行榜