Web. XML configuration error page, and output error message

Source: Internet
Author: User
Tags throwable

1. Need to configure relevant information in Web. xml

[HTML]View Plaincopy print?
  1. <!--default error handling page--
  2. <error-page>
  3. <error-code>403</error-code>
  4. <location>/403.html</location>
  5. </error-page>
  6. <error-page>
  7. <error-code>404</error-code>
  8. <location>/404.html</location>
  9. </error-page>
  10. <!--just stare at commissioning and cannot be commented out during a formal deployment
  11. <!--This configuration is also possible, indicating that a 500 error occurred, go to 500.jsp page processing. -
  12. <error-page>
  13. <error-code>500</error-code>
  14. <location>/500.html</location>
  15. </error-page>
  16. <!--Such a configuration means that if a JSP page or a servlet occurs with an java.lang.Exception type (which of course contains subclasses), the exception goes to 500.jsp page processing. -
  17. <error-page>
  18. <exception-type>java.lang.exception</exception-type>
  19. <location>/500.jsp</location>
  20. </error-page>
  21. <error-page>
  22. <exception-type>java.lang.throwable</exception-type>
  23. <location>/500.jsp</location>
  24. </error-page>
  25. <!--
  26. When both Error-code and Exception-type are configured, the page priority of the Exception-type configuration is high
  27. And a 500 error occurred, the exception exception will jump to 500.jsp
  28. -->
<!--default error Handling page--><error-page><error-code>403</error-code> <location>/403.html</location></error-page><error-page><error-code>404</ error-code><location>/404.html</location></error-page><!--just stare at debugging and cannot be annotated during a formal deployment- ><!--This configuration is also possible, indicating that a 500 error occurred, go to 500.jsp page processing. --><error-page> <error-code>500</error-code> <location>/500.html</location> < /error-page> <!--Such a configuration means that if a JSP page or servlet occurs java.lang.Exception type (of course, it contains subclasses) the exception goes to 500.jsp page processing. --><error-page> <exception-type>java.lang.Exception</exception-type> <location>/500. jsp</location> </error-page> <error-page> <exception-type>java.lang.throwable</ exception-type> <location>/500.jsp</location> </error-page><!-- When both Error-code and Exception-type are configured, the Exception-type configuration has a high page priority and a 500 error, which jumps to 500.jsp--> when an exception exception occurs; 

2. If the configuration is HTML, do not configure it separately

If the configuration is JSP, you need to set Iserrorpage to True,

and <%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "iserrorpage=" true "%>

3. Get exception information and output

[HTML]View Plaincopy print?
  1. <% @page import="java.io.PrintStream"%>
  2. <% @page import="java.io.ByteArrayOutputStream"%>
  3. <%@ include file="web-inf/views/includes/tags.jsp"%>
  4. <%@ page language="java" contenttype="text/html; Charset=utf-8 "
  5. pageencoding="UTF-8" iserrorpage="true"%>
  6. <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd">
  7. <html>
  8. <head>
  9. <Meta http-equiv= "content-type" content= "text/html; Charset=utf-8 ">
  10. <title>500 Server Internal error </title>
  11. </head>
  12. <body>
  13. <div class="Ui-alert-panel">
  14. <H1> server Internal error </H1>
  15. <p> An error occurred while processing your request! Please make sure you are working in the right way. </P>
  16. </div>
  17. <div style="Display:none;" >
  18. <%//Here output exception information
  19. Exception.printstacktrace ();
  20. Bytearrayoutputstream ostr = new Bytearrayoutputstream ();
  21. Exception.printstacktrace (New PrintStream (OSTR));
  22. Out.print (OSTR);
  23. %>
  24. </div>
  25. </body>
  26. </html>
<% @page import= "Java.io.PrintStream"%><% @page import= " Java.io.ByteArrayOutputStream "%><%@ include file=" web-inf/views/includes/tags.jsp "%><%@ page language= "Java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "iserrorpage=" true "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

Web. XML configuration error page, and output error message

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.