真才实料才是最真

Dream have no limit

统计

积分与排名

good link

最新评论

exception对象的简单应用

exception对象的相关应用,以下是空指针异常的捕获
syntax_error.jsp页面
<%@ page contentType="text/html;charset=gb2312" %>
<%--导入JAVA的util包,使用包中的Calendar类;错误连接到exception.jsp--%>
<%@ page import="java.util.*"  errorPage="exception.jsp"%>
<%
Calendar rightNow=null ;//将rightNow设空
rightNow.getTime(); //此行代码会抛出空指针异常
%>

exception.jsp页面(异常捕获)
<%--isErrorPage设置是否使用exception--%>
<%@ page contentType="text/html;charset=gb2312"  isErrorPage="true"%>
<%--导入io包,后面要使用StringWrite和PrintWrite类--%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>错误页面</title>
</head>
<body>
<p><b>exception使用示例</b></p>
<hr size="0">
<font size="-1">
  下面有错误发生,请将错误报告到:liuypo@sei.buaa.edu.cn
</font>
<%  //以下是异常错误轨迹的捕获
    exception.printStackTrace();
    StringWriter sout = new StringWriter();
    PrintWriter pout = new PrintWriter(sout);
    exception.printStackTrace(pout);
%>
<pre>
    <%--显示异常的相关信息--%>
    <%= sout.toString() %>
</pre>
</body>
</html>

posted on 2007-09-03 15:09 gavinkin555 阅读(210) 评论(0)  编辑 收藏 引用 所属分类: JAVA

只有注册用户登录后才能发表评论。