Datasheet
Patrick c01.tex V3 - 09/18/2009 12:15pm Page 26
Chapter 1: Building Web Applications in WebLogic
<filter-class>weblogic.cache.filter.CacheFilter</filter-class>
<init-param>
<param-name>timeout</param-name>
<param-value>60</param-value>
</init-param>
<init-param>
<param-name>key</param-name>
<param-value>parameter.howmany</param-value>
</init-param>
</filter>
...
<filter-mapping>
<filter-name>CacheFilter2</filter-name>
<url-pattern>CacheFilterTest2.jsp</url-pattern>
</filter-mapping>
Accessing this page with a specific value of
howmany
in the query string causes the entire page to be
executed one time. Subsequent page hits with the same
howmany
parameter value will return the same
content without executing the page. Supplying a different value for
howmany
will cause the page to be exe-
cuted for that value and the contents cached using that key value. In other words, if you hit the page five
times with different
howmany
values, you’ve created five different cached versions of the HTTP response
using the
howmany
value as the key. This technique is very slick and very powerful for improving site
performance.
WebLogic Server also includes a
wl:cache
custom tag that provides a very similar caching capability
for any JSP content placed in the body of the custom tag. It has the ability to cache based on key values,
like
CacheFilter
, and can cache small portions of a JSP page rather than an entire page. However, the
CacheFilter
approach has an obvious advantage over the
wl:cache
technique: Caching is performed
using a declarative technique rather than embedding custom tags in the page itself. This defers the def-
inition of caching behavior to deployment time and allows easier control of the caching parameters and
scope using the
web.xml
descriptor elements.
Best Practice
Use the
CacheFilter
instead of
wl:cache
tags for page-level response caching when-
ever possible to provide better flexibility during deployment.
Note that a JSP page included using the
<jsp:include>
action is considered a separate page for the
purposes of caching. It can therefore be configured to cache independently from the parent page, which
may be helpful. Recognize, however, that this included page will not be invoked if the parent page
execution is skipped due to caching. Plan accordingly!
Creating Excel Files Using Servlets and JSP Pages
Creating spreadsheets using servlets and JSP pages is a useful way to provide users with results they
can sort, manipulate, and print using Microsoft Excel or other spreadsheet applications. Servlets are the
preferred mechanism, but JSP pages can also be used if you take steps to avoid unintended newline
characters in the output stream.
26