1. Trang chủ
  2. » Công Nghệ Thông Tin

Addison wesley servlets and javaserver pages the J2EE technology web tier sep 2003 ISBN 0321136497

2 46 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 2
Dung lượng 1,68 MB

Nội dung

Finishing the Site Before moving on, there are a few bits and pieces of the site that need to be addressed The bulk of the site consists of the custom components previously addressed by this chapter All of the custom components required coding from scratch Now we shall address several complementary components that were demonstrated in previous chapters All the components will be relatively simple to implement; instead of coding from scratch, we will simply deploy previously explained code listings The list of things to implement is as follows: site-wide error handling, security, link tracking, caching, compression, and the site's hidden Easter egg Each of the components was completely covered in previous chapters, but each component is briefly rehashed in the following sections as it is installed for use with the book support site Site-Wide Error Handling All of the code previously provided for the book support site uses proper error handling; however, an error can still be thrown (although it probably never will) by the Web Application Should this happen, the container will have to handle the error Normally, as with Tomcat, a stack trace is printed and displayed in a developer-friendly fashion, meaning a cryptic page is shown to a user To prevent this from happening, we need to create a Web Application error page You'll recall in Chapter 4 that this topic was discussed at length The error page needs to be nothing more than a simple JSP or Servlet that is registered via web.xml Listing 15-35 shows a simple error page Listing 15-35 error.jsp [View full width]

Oops!

An error has occurred Information about the problem has been logged and will be handled by administrators as soon as possible If you would like to send further information, please contact support.

The page doesn't do anything fancy It apologetically informs a user that the site has failed to function correctly Additionally, an email address is provided in case the user wishes to communicate further about the problem Save error.jsp in the root directory of the jspbook_site Web Application Deploy the page as the site's default error page by adding Listing 15-36 to web.xml Listing 15-36 Setting error.jsp as the Site's Default Error Page java.lang.Throwable /error.jsp Reload the Web Application for the changes to take effect Now we have a failsafe counter to Tomcat's displaying a cryptic stack trace to use Although it should never happen, plan for the worst You can test the page by browsing http://127.0.0.1/jspbook_site/error.jsp The page provides a polite error message and is rendered with the site's implicit header and footer Figure 15-18 provides a browser rendering of the results in English Figure 15-18 Browser Rendering of the Polite Error Page ... case the user wishes to communicate further about the problem Save error.jsp in the root directory of the jspbook_site Web Application Deploy the page as the site's default error page by adding Listing 15-36 to web. xml Listing 15-36... should never happen, plan for the worst You can test the page by browsing http://127.0.0.1/jspbook_site/error.jsp The page provides a polite error message and is rendered with the site's implicit header and footer... Setting error.jsp as the Site's Default Error Page java.lang.Throwable /error.jsp Reload the Web Application for the changes to take effect

Ngày đăng: 26/03/2019, 17:12