火焰男的BLOG
BlogJava
首页
新随笔
联系
聚合
管理
posts - 2, comments - 5, trackbacks - 0
2006年4月17日
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 @
2006-05-23 13:02
火焰男 阅读(1072) |
评论 (1)
|
编辑
收藏
用JS生成WORD
最近项目中碰到了要自动生成WORD的问题,开始也去找了些开源的东西,比如JACOB,但是它存在一些缺陷。例如它要求JDK在1.4以下,并且还要在设置PATH,比较麻烦,所以最后决定通过客户端的JS来实现需求。
下面是个简单的例子:
<
HTML
>
<
HEAD
>
<
title
>
</
title
>
</
HEAD
>
<
body
>
<
form id
=
"
form
"
>
<
table id
=
"
PrintA
"
width
=
"
100%
"
border
=
"
1
"
cellspacing
=
"
0
"
cellpadding
=
"
0
"
>
<
TR style
=
"
text-align : center;
"
>
<
TD
>
单元格1
</
TD
>
<
TD
>
单元格2
</
TD
>
<
TD
>
单元格3
</
TD
>
<
TD
>
单元格4
</
TD
>
</
TR
>
<
TR
>
<
TD colSpan
=
4
style
=
"
text-align : center;
"
><
font color
=
"
red
"
face
=
"
Verdana
"
>
单元格合并
</
FONT
></
TD
>
</
TR
>
</
TABLE
>
<
BR
>
<
table id
=
"
Test
"
width
=
"
100%
"
>
<
tr
>
<
td
><
font color
=
"
red
"
>
test
</
FONT
></
td
>
</
tr
>
</
table
>
</
form
>
<
input type
=
"
button
"
onclick
=
"
javascript:MakeWord();
"
value
=
"
导出页面到Word
"
>
<
SCRIPT LANGUAGE
=
"
javascript
"
>
function MakeWord()
{
var word
=
new
ActiveXObject(
"
Word.Application
"
);
var doc
=
word .documents.open(
"
http://jazzy:8080/slide/files/jazzy/test.doc
"
);
//
此处为打开已有的模版
或者var doc
=
word .Documents.Add(
""
,
0
,
1
);
//
不打开模版直接加入内容
var oRange
=
doc .Range(
5
,
6
);
var sel
=
document.body.createTextRange();
sel.moveToElementText(form);
//
此处form是页面form的id
sel.select();
sel.execCommand(
"
Copy
"
);
oRange.Paste();
word .Application.Visible
=
true
;
doc .saveAs(
"
http://jazzy:8080/slide/files/jazzy/ba.doc
"
);
//
存放到指定的位置
}
</
SCRIPT
>
</
body
></
html
>
posted @
2006-04-17 16:15
火焰男 阅读(5708) |
评论 (4)
|
编辑
收藏
<
2006年4月
>
日
一
二
三
四
五
六
26
27
28
29
30
31
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
1
2
3
4
5
6
常用链接
我的随笔
我的评论
我的参与
最新评论
留言簿
(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)