JBuilder2005 actual JSP error handling

Source: Internet
Author: User
Tags error handling
Error. jsp
Web applications generally have one or more unified error handling JSP pages, so that users can be informed in a friendly way when an error occurs in a functional JSP page. A friendly and unified error page is an undeniable aspect of the Web presentation layer.
The following code creates the error. jsp file for error handling:
Code List 11 error. jsp error handling JSP page
1. <% @ page contentType = "text/html; charset = GBK" isErrorPage = "true" %>
2. 3. 4. <title> error </title>
5. 6. <body bgcolor = "# ffffff">
7. Sorry, the system has encountered an exception. Click <a href = "login. jsp"> here </a> to return to the home page.
8. </body>
9. The isErrorPage attribute in the page command label of the error handling JSP page should be set to true, as shown in row 1st, so that the exception implicit object can be accessed on the JSP page. In row 3, we use an "elegant" method to report program errors to users and provide a link to return to the logon page.
Now, let's go back and use <% @ page errorPage = "error handling JSP" %> to specify error. jsp as the error handling page of switch. jsp and login. jsp.
After the error handling page is added to the switch. jsp page, the code is as follows:
Code List 12 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 the error handling jsp page is added to the login. JSP page, the code is as follows:
Code List 13 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 SQL query statement of switch. jsp is incorrect and the SQLException exception is thrown, the obscure error page is missing and the following friendly error page is replaced:
Figure 15 friendly error handling page
Failed to log on to fail. jsp
When the user provides an incorrect password, switch. jsp will switch to the fail. jsp page. You can also create the fail. JSP page through the jsp wizard. The code of fail. jsp is as follows:
Code List 14 fail. jsp logon failure page
1. <% @ page contentType = "text/html; charset = GBK" errorPage = "error. jsp" %>
2. 3. 4. <title>
5. fail
6. </title>
7. 8. <body bgcolor = "# ffffff">
9. The password you entered is incorrect. Click <a href = "login. jsp"> here </a> to return to the logon page.
10. </body>
11. After the user password is entered incorrectly, the fail. jsp page is displayed, as shown in the following figure:
Figure 16 fail. jsp page effect

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.