Datasheet

Patrick c01.tex V3 - 09/18/2009 12:15pm Page 13
Chapter 1: Building Web Applications in WebLogic
Web Application Best Practices
Now that you have reviewed some of the key concepts related to web applications in WebLogic Server,
it’s time to dig in and discuss best practices. So many options are available to designers and developers of
Java EE web applications that it would require an entire book to list and explain all of the web application
best practices we could conceivably discuss. In this section, we’ve attempted to discuss the best practices
we feel are applicable to the widest variety of development efforts or are most likely to improve the
quality or performance of your WebLogic Server web applications.
The best practices contained in this chapter cover everything from recommended techniques for using
custom tags to proper packaging of your web application to caching page content for performance.
They are presented in no particular order of importance, because the importance of a given best practice
depends greatly on the particular application you are building.
Ensure Proper Error Handling
Unhandled exceptions that occur during the execution of a servlet or JSP-generated servlet cause the
processing of that page to stop. Assuming the response has not been committed, the JSP output buffer
will be cleared and a new response generated and returned to the client. By default, this error response
contains very little useful information apart from the numeric error code.
What you need is a friendly, informative error page containing as much information as possible to help
during debugging. Fortunately, there is a built-in mechanism for specifying a custom error page for use
in handling server errors during processing.
First, you construct an error page to present the error information to the user in a friendly fashion. At
a minimum, it should display the exception information and a stack trace. To be more useful during
debugging, it can display all request and HTTP header information present using the methods available
on the
HttpServletRequest
object. Portions of an example error page are shown in Listing 1-1. The entire
page is available on the companion web site located at
http://www.wrox.com/
.
Listing 1-1: ErrorPage.jsp.
<%@ page isErrorPage="true" %>
<html>
<head><title>Error During Processing</title></head>
<body>
<h2>An error has occurred during the processing of your request.</h2>
<hr>
<h3><%= exception %></h3>
<pre>
<%
ByteArrayOutputStream ostr = new ByteArrayOutputStream();
exception.printStackTrace(new PrintStream(ostr));
out.print(ostr);
%>
</pre>
Continued
13