In the website often due to the user's improper operation caused by the exception, in general we can put these exceptions in a Web page unified display. This time you need to use the ErrorPage and Iserrorpage attributes.
The purpose of the ErrorPage directive is to specify a Web page in which the JSP program jumps to the specified page when an uncaught exception occurs, and the page that is normally jumped to will need to use Iserrorpage to indicate the error message handling the other page.
Complete the error page operation to meet the following conditions:
1. Specify the jump page when the error occurs (here The Jump page is anerrorpage.jsp), specify by the ErrorPage property
Syntax: <% @page errorpage= "anerrorpage.jsp"%>
2. The error handling page must have an explicit identity, specified by the ErrorPage property
Syntax: <% @page iserrorpage= "true"%>
1 <%@page ContentType="text/html"pageencoding="gb2312"2 ErrorPage="anerrorpage.jsp"%>3 <HTML>4 <Body>5 <%6 //it throws an exception to the anerrorpage, allowing it to handle7 intNum=1/0; 8 %>9 </Body> Ten </HTML>
anerrorpage.jsp
1 <%@page Language="text/html"pageencoding="gb2312" 2 Iserrorpage="true"%>3 <HTML>4 <Body>5 <%6 //Handling Thrown Exceptions7 Out.println ("There is a mathematical operation exception! "); 8 %>9 </Body>Ten </HTML>
Run the final result I will not show, very simple. Here to wake up, the normal situation is can jump, but sometimes there will be unable to jump the problem, the reason is: after the jump, it is possible to anerrorpage think of an error page, so do not display, processing methods:
Setting in Anerrorpage tells the user that it is a normal page
<%response.setstatus (%>)
Jump to find page content changed, but not for anerrorpage.jsp page
Jumps that do not change the address bar are called server-side jumps
To avoid setting errorpage on each page, you can set it in Web. xml:
Format: <error-page>
<error-code>name</error-code>
<location>path</location>
</error-page>
Restart the server after configuration is complete
"Javaweb Learning note 2-jsp error page settings"