Skip to Main Content
Java Enterprise Best Practices
book

Java Enterprise Best Practices

by O'Reilly Java Authors
December 2002
Intermediate to advanced content levelIntermediate to advanced
288 pages
9h 46m
English
O'Reilly Media, Inc.
Content preview from Java Enterprise Best Practices

Prevent Client-Side Caching for Dynamic Pages

Pages that are very dynamic—for instance, a page showing the result of a search based on user input—must not be cached anywhere. As described in Chapter 3, there’s a set of headers you can use to prevent caching of such a response. The problem for JSP pages is the same as described in the previous section, but luckily, the solution is the same as well: let the Controller set the headers for the requests it handles; let JSP pages that are invoked directly set their own headers; and for included pages, let the top-level page set them. Building on the example of a solution for the layout page scenario from the previous section, Example 9-10 shows a variable-setter page that adds caching headers to HashMap collections created by the layout page.

Example 9-10. A variable-setter page that adds caching headers
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
   
<c:set var="subTitle" scope="request" value="Page 1" />
<c:set target="${exp}" property="page1" value="0" />
                  <c:set target="headers" property="Cache-Control" 
  value="no-store, no-cache, must-revalidate, post-check=0, pre-check=0" />
                  <c:set target="headers" property="Pragma" value="no-cache" />

The page in this example adds the value 0 to the collection for expiration dates to ensure that the layout page sets it to a date far in the past. Even if another variable-setter page adds an expiration value for a date in the future, the value 0 is still used because it’s lower. The

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Moving to Java 9: Better Design and Simpler Code

Moving to Java 9: Better Design and Simpler Code

Trisha Gee
Java EE 8 High Performance

Java EE 8 High Performance

Romain Manni-Bucau

Publisher Resources

ISBN: 0596003846Supplemental ContentErrata Page