Datasheet

Patrick c01.tex V3 - 09/18/2009 12:15pm Page 12
Chapter 1: Building Web Applications in WebLogic
When the buffer fills, the response is committed, and the first chunk of information is sent
to the browser. Once this commit occurs, the server will no longer honor
jsp:forward
,
HTTP header changes (such as redirects), or additional cookies. The server will generate an
IllegalStateException
if any of these operations is attempted after the buffer fills and the
response is committed.
The default size of the JSP output buffer is 8KB in WebLogic Server, which you can control using
the
page
directiveineachJSPpage:
<%@ page buffer="32kb" %>
Output buffering may also be turned off using this directive by specifying
none
for a size, but this
practice is not recommended.
Output buffers should be set to at least 32KB in most applications to avoid filling the buffer and
committing the response before the page is complete. The minor additional memory requirement
(32KB times the number of threads) is a small price to pay for correct error page handling and the
ability to add cookies and response headers at any point in large pages.
Best Practice
Always use output buffering in JSP pages. Increase the size of the buffer to at least
32KB to avoid redirect, cookie,
jsp:forward
, and error page problems.
JSP Pages Have Unique Capabilities
Unique capabilities are available in JSP pages that are not present in servlets. The most important of
these is the ability to embed custom XML tags within the JSP page.
Custom tags provide a mechanism to interact with a custom developed Java class that encapsulates
business logic, presentation logic, or both. Custom tag elements are placed in the JSP page by the
developer and then parsed and preprocessed by the application server during the conversion from
JSP to servlet. The tag elements are converted by the server to the Java code required to interact
with the tag class and perform the desired function. Later in this chapter we discuss custom tags
and commonly used tag libraries in more detail and present best practices for their use in WebLogic
Server.
To summarize, JavaServer Pages technology is a scripting language used to create HTML responses.
JSP pages are converted to pure Java servlets by the application server during processing, and they
can perform nearly any task a pure Java servlet can perform. JSP pages also have unique directives,
features, and customization capabilities unavailable to servlets.
Why not use JSP for everything and forget servlets completely? Although it is possible to do
so, servlets often provide a better mechanism for implementing presentation-tier business
logic. Chapter 2 addresses this issue in detail and provides guidance for the proper use of each
technology.
12