程序一:errorPage.jsp<%@ page contentType="text/html; charset=GB2312" %>
<%@ page errorPage="isErrorPage.jsp" %>
<%@ page language="java" %>
<HTML>
<HEAD>
<TITLE>建立错误处理网页</TITLE>
</HEAD>
<BODY>
<CENTER>
<FONT SIZE = 5 COLOR = blue>建立错误处理网页</FONT>
</CENTER>
<BR>
<HR>
<BR>
<%
String strdividend = request.getParameter("dividend");
String strdivisor = request.getParameter("divisor"); 
if (strdividend == null || strdivisor == null )
{
%>
<Form action="errorPage.jsp" method=post>
<P><INPUT type="text" name=dividend>
除以<INPUT type="text" name=divisor></P>
<INPUT type=submit name=submit1 value=送出>
</Form>
<%
}
else
{
try{
int dividend = Integer.parseInt(strdividend);
int divisor = Integer.parseInt(strdivisor); 
%>
<H3>答案为<Font color = red>
<%= dividend / divisor%></Font></H3>
<%
}
catch(NumberFormatException nfex)
{
throw new NumberFormatException("您输入的不是整数");
}
catch(RuntimeException rtex)
{
throw new RuntimeException("不可输入0");
}
}
%>
</BODY>
</HTML>程序二:isErrorPage.jsp<%@ page contentType="text/html; charset=GB2312" %>
<%@ page isErrorPage = "true" %>
<%@ page language="java" %>
<HTML>
<HEAD>
<TITLE>建立错误处理网页</TITLE>
</HEAD>
<BODY>
<CENTER>
<FONT SIZE = 5 COLOR = blue>建立错误处理网页</FONT>
</CENTER>
<BR>
<HR>
<BR>
<CENTER>
<FONT SIZE=4 COLOR=RED>
<%= exception.toString() %>
</CENTER>
</FONT>
</BODY>
</HTML>出现这样的问题:在被除数那栏输入0;或者除数和被除数都为空;运行不了,显示“网页无法显示”。其它合规则的如1/1=0就可以运行。为什么?程序没发现错误。

解决方案 »

  1.   

    在你的错误处理页面增加一行
    <%response.setStatus(HttpServletResponse.SC_OK); 请参考这个http://www.java2000.net/viewthread.jsp?tid=184
      

  2.   

    按你的方法加上去了。又出错了:type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 4 in the jsp file: /example/13/isErrorPage.jsp
    Generated servlet error:
    D:\workspace\MyProject\bin\org\apache\jsp\example\_13\isErrorPage_jsp.java:50: generics are not supported in -source 1.3
    (try -source 1.5 to enable generics)
    <HTML>
    ^
    An error occurred at line: 4 in the jsp file: /example/13/isErrorPage.jsp
    Generated servlet error:
    D:\workspace\MyProject\bin\org\apache\jsp\example\_13\isErrorPage_jsp.java:51: illegal start of expression
    <HEAD>
    ^
    2 errors org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
    org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:437)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:497)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:476)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:464)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:691)
    org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:658)
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:806)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
    org.apache.jsp.example._13.errorPage_jsp._jspService(errorPage_jsp.java:103)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.0.30 logs.
      

  3.   

    An error occurred at line: 4第四行就是:<%response.setStatus(HttpServletResponse.SC_OK);
      

  4.   

    generics   are   not   supported   in   -source   1.3 
    (try   -source   1.5   to   enable   generics) 你应该更新你的JDK了!!或者修改你的编译器,不要和1.3兼容了