JSP错误页面exception总是为空的问题?
之前在其它的项目中使用过这种方法一直好使,但这次不知道为啥会出现这种情况:
第一步:
自定义了异常体系为:
-com.swc.se.exception
+SeDAOException(继承自SeException)
+SeException(继承自
RuntimeException)
SeException:
public class SeException extends RuntimeException
{
public SeException(String message )
{
super(message);
}
}
SeDAOException:
public class SeDAOException extends SeException
{
public SeDAOException(String message)
{
super(message);
}
}
第二步:
错误页面为:
<%@ page contentType= "text/html;charset=gb2312 " %>
<%@ page isErrorPage= "true " %>
<html>
<head>
<title> 错误信息! </title>
<meta http-equiv= "content-type " content= "text/html;charset=gb2312 ">
</head>
<body>
<center>
<h1> 错误信息! </h1>
<br>
<table width= "500 ">
<%
if(exception!=null)
{
%>
<tr>
<td colspan= "2 " class= "warnning ">
<%=exception.getMessage()%>
</td>
</tr>
<%
}
out.println( "exception为null ");
%>
<tr>
<td align= "center " colspan= "2 ">
<p>
<input type= "button " name= "register " value= "返回 " onclick= "javascript:history.go(-1); ">
</td>
</tr>
<tr>
<td align= "right " colspan= "2 ">
<img height= "200 " src= "images/welcome.gif ">
</td>
</tr>
</table>
</center>
</body>
</html>
第三步:
修改web.xml:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<web-app version= "2.4 " xmlns= "http://java.sun.com/xml/ns/j2ee "
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<servlet>
<description>
</description>
<display-name> login </display-name>
<servlet-name> ConsumerLoginServlet </servlet-name>
<servlet-class>
com.swc.se.controller.ConsumerLoginServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> ConsumerLoginServlet </servlet-name>
<url-pattern> /ConsumerLoginServlet </url-pattern>
</servlet-mapping>
...
<error-page>
<exception-type>
com.swc.se.exception.SeAuth