<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 30, 文章 - 0, 評論 - 27, 引用 - 0
    數據加載中……

    web.xml 配置404和500錯誤的自定義頁面

    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頁面的關鍵在于

    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* 本頁面是在客戶查找的頁面無法找到的情況下調用的
     6*/

     7response.setStatus(HttpServletResponse.SC_OK);
     8%>
     9<body>
    10正在制作 <a href="javascript:history.go(-1)">返回</a>
    11<br/>
    12也可能頁面連接更改了,請按 F5 鍵刷新整個頁面看看,特別是菜單!
    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程序發生了錯誤,有可能該頁面正在調試或者是設計上的缺陷.<br/>
     6你可以選擇<br/> <a href=<%=request.getContextPath()+"/forum/new.jsp" %>>反饋</a>
     7提醒我 或者<br/><a href="javascript:history.go(-1)">返回上一頁</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>





    文章轉自:http://blog.csdn.net/java2000_net/archive/2007/12/29/2000965.aspx

    posted on 2008-01-09 22:33 石業海 閱讀(34621) 評論(2)  編輯  收藏 所屬分類: 其它

    評論

    # re: web.xml 配置404和500錯誤的自定義頁面   回復  更多評論   

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

    # re: web.xml 配置404和500錯誤的自定義頁面   回復  更多評論   

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

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲精品97久久中文字幕无码| 88xx成人永久免费观看| 97在线线免费观看视频在线观看| 狠狠色伊人亚洲综合成人| 两性色午夜视频免费网| 亚洲人成精品久久久久| 少妇性饥渴无码A区免费| 亚洲成A∨人片在线观看不卡| 免费看成人AA片无码视频吃奶| 亚洲成av人影院| 久久99国产综合精品免费| 亚洲成a人片在线观看中文!!! | 182tv免费视视频线路一二三| 亚洲精品视频在线| 亚洲一级免费视频| 一本色道久久综合亚洲精品蜜桃冫| 精品少妇人妻AV免费久久洗澡| 苍井空亚洲精品AA片在线播放| 毛茸茸bbw亚洲人| 日本免费在线中文字幕| 亚洲一线产区二线产区精华| 在线播放高清国语自产拍免费 | 亚洲欧美中文日韩视频| 四虎免费久久影院| 久久久国产精品福利免费| 国产精品免费视频观看拍拍| 国产成人亚洲精品青草天美| 免费福利在线播放| 女bbbbxxxx另类亚洲| 久久久久久久综合日本亚洲 | 一级做a爰片久久毛片免费看| 亚洲国产精品无码专区在线观看| 日本片免费观看一区二区| 老外毛片免费视频播放| 亚洲AV无码国产精品麻豆天美| 性色av无码免费一区二区三区| 国产免费MV大全视频网站| 亚洲国产精品美女| 亚洲无线码在线一区观看| 无码日韩人妻av一区免费| 久久久久国色AV免费观看|