隨筆 - 30, 文章 - 0, 評(píng)論 - 27, 引用 - 0
          數(shù)據(jù)加載中……

          web.xml 配置404和500錯(cuò)誤的自定義頁(yè)面

          web.xml

           1<?xml version="1.0" encoding="UTF-8"?>
           2<web-app version="2.4" 
           3    xmlns="http://java.sun.com/xml/ns/j2ee" 
           4    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           5    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
           6    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
           7    
           8<error-page>
           9    <error-code>404</error-code>
          10    <location>/building.jsp</location>
          11</error-page>
          12
          13<error-page>
          14    <error-code>500</error-code>
          15    <location>/error.jsp</location>
          16</error-page>
          17    
          18</web-app>
          19

           

           

          JSP頁(yè)面的關(guān)鍵在于

          1 isErrorPage="true"

          2 response.setStatus(HttpServletResponse.SC_OK);

          building.jsp

           

           1<%@ page language="java" contentType="text/html; charset=GBK" isErrorPage="true" pageEncoding="GBK"%>
           2<%response.setStatus(HttpServletResponse.SC_OK);%>
           3<%
           4/**
           5* 本頁(yè)面是在客戶查找的頁(yè)面無(wú)法找到的情況下調(diào)用的
           6*/

           7response.setStatus(HttpServletResponse.SC_OK);
           8%>
           9<body>
          10正在制作 <a href="javascript:history.go(-1)">返回</a>
          11<br/>
          12也可能頁(yè)面連接更改了,請(qǐng)按 F5 鍵刷新整個(gè)頁(yè)面看看,特別是菜單!
          13</body>

           

          error.jsp

           1<%@ page language="java" contentType="text/html; charset=GBK" isErrorPage="true" pageEncoding="GBK"%>
           2<%@ page import="java.io.*,java.util.*"%>
           3<%response.setStatus(HttpServletResponse.SC_OK);%>
           4<body>
           5程序發(fā)生了錯(cuò)誤,有可能該頁(yè)面正在調(diào)試或者是設(shè)計(jì)上的缺陷.<br/>
           6你可以選擇<br/> <a href=<%=request.getContextPath()+"/forum/new.jsp" %>>反饋</a>
           7提醒我 或者<br/><a href="javascript:history.go(-1)">返回上一頁(yè)</a>
           8<hr width=80%>
           9<h2><font color=#DB1260>JSP Error Page</font></h2>
          10<p>An exception was thrown: <b> <%=exception.getClass()%>:<%=exception.getMessage()%></b></p>
          11<%
          12Enumeration<String> e = request.getHeaderNames();
          13String key;
          14while(e.hasMoreElements()){
          15  key = e.nextElement();
          16}

          17= request.getAttributeNames();
          18while(e.hasMoreElements()){
          19  key = e.nextElement();
          20}

          21= request.getParameterNames();
          22while(e.hasMoreElements()){
          23  key = e.nextElement();
          24}

          25%>
          26<%=request.getAttribute("javax.servlet.forward.request_uri"%><br>
          27<%=request.getAttribute("javax.servlet.forward.servlet_path"%>
          28<p>With the following stack trace:</p>
          29<pre>
          30<%
          31  exception.printStackTrace();
          32  ByteArrayOutputStream ostr = new ByteArrayOutputStream();
          33  exception.printStackTrace(new PrintStream(ostr));
          34  out.print(ostr);
          35%>
          36</pre>
          37<hr width=80%>
          38</body>





          文章轉(zhuǎn)自:http://blog.csdn.net/java2000_net/archive/2007/12/29/2000965.aspx

          posted on 2008-01-09 22:33 石業(yè)海 閱讀(34613) 評(píng)論(2)  編輯  收藏 所屬分類(lèi): 其它

          評(píng)論

          # re: web.xml 配置404和500錯(cuò)誤的自定義頁(yè)面   回復(fù)  更多評(píng)論   

          大師 問(wèn)一下 我用您的方法 為什么500錯(cuò)誤的可以 而404的怎么也不行 請(qǐng)幫我解答一下吧 謝謝 qq379878654
          2008-08-04 16:37 | 張麗云

          # re: web.xml 配置404和500錯(cuò)誤的自定義頁(yè)面   回復(fù)  更多評(píng)論   

          goodgood boy!
          2013-07-17 11:53 | feilian09

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 泽州县| 南靖县| 财经| 吉水县| 霍邱县| 福海县| 宜都市| 涿州市| 张家港市| 和田市| 大同市| 根河市| 自贡市| 理塘县| 仪陇县| 襄樊市| 长沙县| 苍梧县| 蓬莱市| 九江市| 出国| 达州市| 永泰县| 临西县| 当阳市| 兰西县| 宁陕县| 庆元县| 久治县| 崇义县| 息烽县| 三门县| 灵山县| 交口县| 鱼台县| 普定县| 丽江市| 新宾| 怀来县| 左云县| 临江市|