"Javaweb Learning note 2-jsp error page settings"

Source: Internet
Author: User

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"

Related Article

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.