Error handling of JBuilder2005 actual combat JSP

Source: Internet
Author: User
Tags error handling
Error-handling page error.jsp

Web applications typically have one or more unified error-handling JSP pages that provide a friendly form of feedback to the user in the event of a functional JSP page error. A friendly and unified error page is an area of the Web presentation layer that can be ignored.

Below, we create the error-handling error.jsp file, whose code looks like this:

Code list error.jsp error handling JSP page

1. <% @page contenttype= "text/html; CHARSET=GBK "iserrorpage=" true "%>
2. The 3. The 4. <title> Error </title>
5. The 6. <body bgcolor= "#ffffff"
7. Sorry, the system has been abnormal, click <a Href= "Login.jsp" > here </a> back to Home
8. The </body>
9. The The Iserrorpage property in the Page directive tab of the error-handling JSP page should be set to true, as shown in line 1th, so that the exception suppressed object can be accessed in the JSP page. On line 7th, we report the program error to the user in an "elegant" manner and provide a link back to the login page.

Now, let's go back and specify error.jsp as the error-handling page for switch.jsp and login.jsp through the <%@ page errorpage= error handling JSP%>.

After adding an error-handling page to the switch.jsp page, the code is as follows:

Code Listing switch.jsp Add error handling JSP page

1. <% @page contenttype= "text/html; CHARSET=GBK "errorpage=" error.jsp "%>
2. <% @page import= "bookstore.*"%>
3. <% @page import= "java.sql.*"%>
4...
After adding an error-handling JSP page to the login.jsp page, the code is as follows:

Code Listing login.jsp Add error handling page

1. <% @page contenttype= "text/html; CHARSET=GBK "errorpage=" error.jsp "%>
2. <% @page errorpage= "error_error.jsp"%>
3...
In this way, when the switch.jsp SQL query statement incorrectly throws the SqlException exception, the obscure Anomaly information error page is missing and replaced by the following user-friendly error page:


Figure 15 Friendly error-handling page
Login Failed fail.jsp

When the user provides incorrect password, switch.jsp will turn to fail.jsp page, also you can create fail.jsp page through the JSP Wizard, fail.jsp code is as follows:

Code list fail.jsp Login Failure page

1. <%@ page contenttype= "text/html; CHARSET=GBK "errorpage=" error.jsp "%>
2. The 3. The 4. The <title>
5. Fail
6. The </title>
7. The 8. <body bgcolor= "#ffffff"
9. You entered the wrong password, click <a Href= "Login.jsp" > here </a> return to the login page.
-</body>
One. When the user password is entered incorrectly, the fail.jsp page effect is seen, as shown in the following illustration:


Figure fail.jsp Page Effects
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.