1, using JSP mode
If the configuration is JSP, you need to set Iserrorpage to True,
and set <%@ page language= "Java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "iserrorpage=" true "%>
Error page:
<% @pageImport= "Java.io.PrintStream"%> <% @pageImport= "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" > class= "Ui-alert-panel" > //Output exception information hereException.printstacktrace (); Bytearrayoutputstream Ostr=NewBytearrayoutputstream (); Exception.printstacktrace (NewPrintStream (OSTR)); Out.print (OSTR); %> </div> </body> errorpage.jspYou can use this page to trigger the error above:
<!-- --><%@ page language= "java" contenttype= "text/html; charset=utf-8" pageencoding = "UTF-8" errorpage= "errorpage.jsp"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" > NULL ; A.tostring (); // make a mistake %></body>
home.jsp2, you can also use the configuration XML method:
<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee/http Java.sun.com/xml/ns/javaee/web-app_3_0.xsd "version=" 3.0 "> <display-name>day06_jspdemo1</ display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> </ Welcome-file-list> <!--exception state handling for a project-<!--default error Handling page--<error-page> <error-code>403</error-code> <location>/403.html</location> </error-page> <error-page> & Lt;error-code>404</error-code> <location>/404.html</location> </ERROR-PAGE&G T <!--just look at debugging and not comment-<!--in a formal deployment, which means that the 500 error occurs when you go to 500.jsp page processing. -<error-page> <error-code>500</error-code> <LOCATION>/5 00.html</location> </error-page> <!--This configuration means that if a JSP page or servlet occurs JAVA.LANG.EXCE Exceptions to the Ption type (which of course contain subclasses) go 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& Gt </error-page> <!--when errorWhen both-code and Exception-type are configured, the exception-the type is configured with a high page priority and a 500 error, which jumps to 500.jsp when an exception occurs exception-</web-app>
Web. XMLError pages can also be written on their own, we can also introduce public welfare 404 pages, such as:
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 " pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >// This setting can cheat IE browser, let IE browser successfully display public welfare 404 page response.setstatus ($); %></body>
500.jspOriginal link: web. XML Configuration Error page
"JSP" Configuration error page