最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > jsp教程

JSP里实现错误处理页面的制作404和500

日期:01-08    来源:中国设计秀    作者:cnwebshow.com

web.xml文件增加如下代码查看复制到剪切板打印U1L中国设计秀
<error-page>   U1L中国设计秀
        <error-code>404</error-code>   U1L中国设计秀
        <location>/building.jsp</location>   U1L中国设计秀
</error-page>   U1L中国设计秀
<error-page>   U1L中国设计秀
        <error-code>500</error-code>   U1L中国设计秀
        <location>/error.jsp</location>   U1L中国设计秀
</error-page> U1L中国设计秀

        <error-page>U1L中国设计秀
                <error-code>404</error-code>U1L中国设计秀
                <location>/building.jsp</location>U1L中国设计秀
        </error-page>U1L中国设计秀
        <error-page>U1L中国设计秀
                <error-code>500</error-code>U1L中国设计秀
                <location>/error.jsp</location>U1L中国设计秀
        </error-page>building.jsp查看复制到剪切板打印U1L中国设计秀
<%@ page language="java" contentType="text/html; charset=GBK" isErrorPage="true" pageEncoding="GBK"%>   U1L中国设计秀
<%   U1L中国设计秀
  response.setStatus(HttpServletResponse.SC_OK);   U1L中国设计秀
%>   U1L中国设计秀
对不起,您请求的页面没有找到! U1L中国设计秀

<%@ page language="java" contentType="text/html; charset=GBK" isErrorPage="true" pageEncoding="GBK"%>U1L中国设计秀
<%U1L中国设计秀
  response.setStatus(HttpServletResponse.SC_OK);U1L中国设计秀
%>U1L中国设计秀
对不起,您请求的页面没有找到!error.jsp查看复制到剪切板打印U1L中国设计秀
<%@ page language="java" contentType="text/html; charset=GBK" isErrorPage="true" pageEncoding="GBK"%>   U1L中国设计秀
<%@ page import="java.io.*,java.util.*"%>   U1L中国设计秀
<%response.setStatus(HttpServletResponse.SC_OK);   U1L中国设计秀
  U1L中国设计秀
      %>   U1L中国设计秀
<body>   U1L中国设计秀
程序发生了错误,有可能该页面正在调试或者是设计上的缺陷.   U1L中国设计秀
  U1L中国设计秀
你可以选择   U1L中国设计秀
 <a href=<%=request.getContextPath()+"/forum/new.jsp" %>>反馈</a>   U1L中国设计秀
提醒我... 或者   U1L中国设计秀
<a href="javascript:history.go(-1)">返回上一页</a>   U1L中国设计秀
<hr width=80%>   U1L中国设计秀
<h2><font color=#DB1260>JSP Error Page</font></h2>   U1L中国设计秀
  U1L中国设计秀
<p>An exception was thrown: <b> <%=exception.getClass()%>:<%=exception.getMessage()%></b></p>   U1L中国设计秀
<%   U1L中国设计秀
System.out.PRintln("Header....");   U1L中国设计秀
Enumeration<String> e = request.getHeaderNames();   U1L中国设计秀
String key;   U1L中国设计秀
while(e.hasMoreElements()){   U1L中国设计秀
  key = e.nextElement();   U1L中国设计秀
  System.out.println(key+"="+request.getHeader(key));   U1L中国设计秀
}   U1L中国设计秀
System.out.println("Attribute....");   U1L中国设计秀
e = request.getAttributeNames();   U1L中国设计秀
while(e.hasMoreElements()){   U1L中国设计秀
  key = e.nextElement();   U1L中国设计秀
  System.out.println(key+"="+request.getAttribute(key));   U1L中国设计秀
}   U1L中国设计秀
  U1L中国设计秀
System.out.println("arameter....");   U1L中国设计秀
e = request.getParameterNames();   U1L中国设计秀
while(e.hasMoreElements()){   U1L中国设计秀
  key = e.nextElement();   U1L中国设计秀
  System.out.println(key+"="+request.getParameter(key));   U1L中国设计秀
}   U1L中国设计秀
%>   U1L中国设计秀
111<%=request.getAttribute("javax.servlet.forward.request_uri") %>   U1L中国设计秀
  U1L中国设计秀
<%=request.getAttribute("javax.servlet.forward.servlet_path") %>   U1L中国设计秀
  U1L中国设计秀
<p>With the following stack trace:</p>   U1L中国设计秀
<pre>   U1L中国设计秀
<%exception.printStackTrace();   U1L中国设计秀
      ByteArrayOutputStream ostr = new ByteArrayOutputStream();   U1L中国设计秀
      exception.printStackTrace(new PrintStream(ostr));   U1L中国设计秀
      out.print(ostr);   U1L中国设计秀
    %>   U1L中国设计秀
</pre>   U1L中国设计秀
<hr width=80%>   U1L中国设计秀
</body> U1L中国设计秀

本文引用地址:/bc/article_46580.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明