火焰男的BLOG
BlogJava
首页
新随笔
联系
聚合
管理
posts - 2, comments - 5, trackbacks - 0
webwork统一处理异常
webwork提供了异常的统一拦截机制,只需要在xwork.xml中写如下代码
<
interceptor name
=
"
exception
"
class
=
"
com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor
"
/>
<
global
-
results
>
<
result name
=
"
my
DaoExceptionPage
"
type
=
"
dispatcher
"
>
<
param name
=
"
location
"
>/
WEB
-
INF
/
vm
/
common
/
wafExceptionPage.jsp
</
param
>
</
result
>
<
result name
=
"
my
ServiceExceptionPage
"
type
=
"
dispatcher
"
>
<
param name
=
"
location
"
>/
WEB
-
INF
/
vm
/
common
/
wafExceptionPage.jsp
</
param
>
</
result
>
<
result name
=
"
my
ActionExceptionPage
"
type
=
"
dispatcher
"
>
<
param name
=
"
location
"
>/
WEB
-
INF
/
vm
/
common
/
wafExceptionPage.jsp
</
param
>
</
result
>
<
result name
=
"
my
ExceptionPage
"
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
=
"
my
DaoExceptionPage
"
/>
<
exception
-
mapping name
=
"
exceptionPage
"
exception
=
"
net.jite.waf.persistent.exception.MyServiceException
"
result
=
"
my
ServiceExceptionPage
"
/>
<
exception
-
mapping name
=
"
exceptionPage
"
exception
=
"
net.jite.waf.persistent.exception.MyActionException
"
result
=
"
my
ActionExceptionPage
"
/>
</
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
火焰男
阅读(1072)
评论(1)
编辑
收藏
FeedBack:
#
re: webwork统一处理异常
2008-08-29 10:54 |
hnbczr
getValueStack()这个方法是什么意思?
回复
更多评论
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
知识库
C++博客
博问
管理
<
2006年5月
>
日
一
二
三
四
五
六
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
常用链接
我的随笔
我的评论
我的参与
最新评论
留言簿
(2)
给我留言
查看公开留言
查看私人留言
随笔档案
(2)
2006年5月 (1)
2006年4月 (1)
文章档案
(1)
2006年4月 (1)
相册
北京之行
其他人的blog
BlueDavy
jazzy
最新随笔
1. webwork统一处理异常
2. 用JS生成WORD
搜索
积分与排名
积分 - 7123
排名 - 2731
最新评论
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
阅读排行榜
1. 用JS生成WORD(5708)
2. webwork统一处理异常(1072)
评论排行榜
1. 用JS生成WORD(4)
2. webwork统一处理异常(1)