本站不再更新,歡迎光臨 java開發(fā)技術(shù)網(wǎng)
          隨筆-230  評(píng)論-230  文章-8  trackbacks-0
          jsp中錯(cuò)誤處理頁(yè)面


          舉例說明:mustBeError.jsp
          <%@ page contentType="text/html; charset=gb2312"
          language=
          "java"import="java.sql.*,javax.servlet.*,javax.servlet.http.*" errorPage="error.jsp" %>
          <%
          //這個(gè)頁(yè)面一定會(huì)出錯(cuò)。
          int i=0;
          int j=1;
          out.println(j/i);
          %>


          在此中通過errorPage=
          "error.jsp"來指定出錯(cuò)時(shí)錯(cuò)誤處理頁(yè)面


          <--------------------------->
          error.jsp

          <%@ page contentType=
          "text/html; charset=gb2312" language="java" isErrorPage="true"import="java.io.*"%>
          <html>
          <head>
          <title>出錯(cuò)了!</title>
          <meta http-equiv=
          "Content-Type" content="text/html; charset=gb2312">
          </head>
          <body>
          出錯(cuò)了!<br>
          發(fā)生了以下的錯(cuò)誤:
          <br><hr><font color=red><hr>
          getMessage():<br>
          <%=exception.getMessage()%><br><hr>
          getLocalizedMessage():<br>
          <%=exception.getLocalizedMessage()%><br><hr>
          PrintStatckTrace():<br>
          <%
          StringWriter sw=new StringWriter();
          PrintWriter pw=new PrintWriter(sw);
          exception.printStackTrace(pw);
          out.println(sw);
          %><br>
          </font></body>
          </html>


          在error.jsp中,page指令中指定:isErrorPage=
          "true"

          <---------------------->
          在web.xml中聲明異常和錯(cuò)誤頁(yè)面

          例如:
          <?xml version=
          "1.0" encoding="ISO-8859-1"?>

          <web-app 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 web-app_2_4.xsd"
          version=
          "2.4">
          <error-page>
          <error-code>404</error-code>
          <location>/pageNotFound.html</location>
          </error-page>

          <error-page>
          <exception-type>java.lang.NumberFormatException</exception-type>
          <location>/NumberFormatException.html</location>
          </error-page>

          </web-app>

          說明:指定錯(cuò)誤代碼為404是,調(diào)用/pageNotFound.html
          也可以指定錯(cuò)誤類型如:java.lang.NumberFormatException,出現(xiàn)此錯(cuò)誤類型是調(diào)用/NumberFormatException.html
          posted on 2006-06-15 11:44 有貓相伴的日子 閱讀(1025) 評(píng)論(0)  編輯  收藏 所屬分類: j2ee
          本站不再更新,歡迎光臨 java開發(fā)技術(shù)網(wǎng)
          主站蜘蛛池模板: 西青区| 运城市| 盘山县| 盐山县| 常州市| 当阳市| 武川县| 邵武市| 蓬安县| 公主岭市| 沁阳市| 腾冲县| 桑日县| 乌鲁木齐县| 新河县| 广河县| 体育| 荃湾区| 涪陵区| 衡山县| 和顺县| 萝北县| 嘉峪关市| 商城县| 神池县| 廊坊市| 武宣县| 格尔木市| 察隅县| 太仆寺旗| 甘洛县| 花莲市| 抚远县| 古田县| 蓬溪县| 增城市| 苗栗县| 桃园市| 甘谷县| 西乌珠穆沁旗| 曲靖市|