How to declare and use error handling pages in JSP

Source: Internet
Author: User

We know that a website made by Java Web will inevitably have improper operations when users are using it, these improper operations may expose the path of the WEB Project (that is, the browser prompts errors such as 500 ). To prevent this situation and protect Java Web websites, we will write an error. jsp page in advance when designing a Java Web website. When an error occurs on the page, the error. jsp page is redirected to the page for processing, instead of the Error 500.

We need to do two things:

1. Error. jsp

<% @ Page contenttype = "text/html; charset = gb2312" Language = "Java" iserrorpage = "true" Import = "Java. io. * "%> <HTML>  

Why is this page called error. jsp? It is because there is a parameter named iserrorpage = "true" in the second line. It clearly means whether the page is an error page.

2. What changes do other pages need to be made?

When a JSP page fails, how can it jump to the error. jsp page? The answer is to add the following tag to the header of the page (non-error. jsp:

<% @ Page contenttype = "text/html; charset = gb2312" Language = "Java" errorpage = "error. jsp" %>

We can see that there is an errorpage attribute. Set this attribute value to error. jsp.

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.