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. <html> 3. <head> 4. <title>error</title> 5. </head> 6. <body bgcolor="#ffffff"> 7. 抱歉,系统发生异常,点击<a href="login.jsp">这儿</a>返回首页 8. </body> 9. </html> 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:
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:
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. <html> 3. <head> 4. <title> 5. fail 6. </title> 7. </head> 8. <body bgcolor="#ffffff"> 9. 你输入的密码不正确,点击<a href="login.jsp">这儿</a>返回登录页面。 10. </body> 11. </html> When the user password is entered incorrectly, the fail.jsp page effect is seen, as shown in the following illustration:
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.