大家都知道吧
在struts
中提供了一些常用的******
其中就包括对异常处理的******
我们直接声明使用即可
很方便的哟!下面来举个例子说明一下
strutsxml
<!DOCTYPE struts PUBLIC //Apache Software Foundation//DTD Struts Configuration //EN dtd>
<struts>
<! 对默认******的引入 >
<include file=strutsdefaultxml />
<package name=eticket extends=strutsdefault>
<! 全局异常映射 >
<globalexceptionmappings>
<exceptionmapping result=error exception=javalangException>
</exceptionmapping>
</globalexceptionmappings>
<action name=airTicketAction class=AirTicketAction>
<result>airticket/airticketjsp</result>
<result name=detail>airticket/airticketdetailjsp</result>
<result name=order>airticket/airticketorderjsp</result>
<result name=error>errorjsp</result>
<! 局部异常映射 >
<exceptionmapping result=nullPoint exception=javalangNullPointerException></exceptionmapping>
<result name=nullPoint>errorjsp</result>
</action>
</package>
</struts>
下面是一个action产生一个异常用于测试
AirTicketActionjava
import comopensymphonyxworkActionSupport;
@SuppressWarnings(serial)
public class AirTicketAction extends ActionSupport {
@Override
public String execute() throws Exception {
// TODO 自动生成方法存根
//产生一个除数为的异常
int i = /;
return SUCCESS;
}
}
用于显示的jsp页面
errorjsp
<%@ page language=java contentType=text/html; charset=UTF pageEncoding=UTF%>
<%@ taglib prefix=s uri=/strutstags%>
<!DOCTYPE HTML PUBLIC //WC//DTD HTML Transitional//EN>
<html>
<head>
<meta httpequiv=ContentType content=text/html; charset=UTF>
<title><s:text name=logintitle></s:text></title>
</head>
<body>
<h>出错了!</h>
<s:property value=ssage />
<s:property value=exceptionStack />
</body>
</html>
很简单配置完成可以使用了