大家都知道吧
在struts
中提供了一些常用的******
其中就包括對異常處理的******
我們直接聲明使用即可
很方便的喲!下面來舉個例子說明一下
struts
xml
<!DOCTYPE struts PUBLIC
//Apache Software Foundation//DTD Struts Configuration
//EN
dtd
>
<struts>
<!
對默認******的引入
>
<include file=
struts
default
xml
/>
<package name=
eticket
extends=
struts
default
>
<!
全局異常映射
>
<global
exception
mappings>
<exception
mapping result=
error
exception=
java
lang
Exception
>
</exception
mapping>
</global
exception
mappings>
<action name=
airTicketAction
class=
AirTicketAction
>
<result>airticket/airticket
jsp</result>
<result name=
detail
>airticket/airticketdetail
jsp</result>
<result name=
order
>airticket/airticketorder
jsp</result>
<result name=
error
>error
jsp</result>
<!
局部異常映射
>
<exception
mapping result=
nullPoint
exception=
java
lang
NullPointerException
></exception
mapping>
<result name=
nullPoint
>error
jsp</result>
</action>
</package>
</struts>
下面是一個action
產生一個異常
用於測試
AirTicketAction
java
import com
opensymphony
xwork
ActionSupport;
@SuppressWarnings(
serial
)
public class AirTicketAction extends ActionSupport {
@Override
public String execute() throws Exception {
// TODO 自動生成方法存根
//產生一個除數為
的異常
int i =
/
;
return SUCCESS;
}
}
用於顯示的jsp頁面
error
jsp
<%@ page language=
java
contentType=
text/html; charset=UTF
pageEncoding=
UTF
%>
<%@ taglib prefix=
s
uri=
/struts
tags
%>
<!DOCTYPE HTML PUBLIC
//W
C//DTD HTML
Transitional//EN
>
<html>
<head>
<meta http
equiv=
Content
Type
content=
text/html; charset=UTF
>
<title><s:text name=
login
title
></s:text></title>
</head>
<body>
<h
>出錯了!</h
>
<s:property value=
ssage
/>
<s:property value=
exceptionStack
/>
</body>
</html>
很簡單
配置完成可以使用了
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28685.html