Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
2.8 An Example Using Servlet Initialization and Page Modification Dates
45
Figure 2 8
Output of LotteryNumbers servlet.
with Java dates. The time is automatically converted to a date in GMT appro
priate for the
Last Modified
header. More importantly, if the server receives
a conditional
GET
request (one specifying that the client only wants pages
marked
If Modified Since
a particular date), the system compares the
specified date to that returned by
getLastModified
, only returning the page
if it has been changed after the specified date. Browsers frequently make these
conditional requests for pages stored in their caches, so supporting conditional
requests helps your users as well as reducing server load. Since the
Last Mod
ified
and
If Modified Since
headers use only whole seconds, the
get
LastModified
method should round times down to the nearest second.
Figures 2 9 and 2 10 show the result of requests for the same servlet with
two slightly different
If Modified Since
dates. To set the request headers
and see the response headers, I used
WebClient
, a Java application shown in
Section 2.10 (WebClient: Talking to Web Servers Interactively) that lets you
interactively set up HTTP requests, submit them, and see the results.
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved