The Artima Developer Community
Sponsored Link

Java Answers Forum
Cache Control in servlets and jsp

1 reply on 1 page. Most recent reply: Oct 29, 2003 11:29 AM by Noone nonsense

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
krishnamoorthys

Posts: 2
Nickname: krishnamoo
Registered: Oct, 2003

Cache Control in servlets and jsp Posted: Oct 29, 2003 11:18 AM
Reply to this message Reply
Advertisement
How to Control cache in users browser ?


Noone nonsense

Posts: 5
Nickname: desmin
Registered: Mar, 2003

Re: Cache Control in servlets and jsp Posted: Oct 29, 2003 11:29 AM
Reply to this message Reply
To prevent Web browsers and proxy servers from caching dynamically generated Web pages (meaning dynamic output that results from processing JSP files, SHTML files, and servlets), use the following code to set headers in the HTTP Response:

<%
response.setHeader("Pragma", "No-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-cache");
%>

Setting the HTTP headers is a more effective method of controlling browser caching than using the <META> tag equivalents. For example,
<META HTTP-EQUIV="Pragma" CONTENT="No-cache">

is the equivalent of the first HTTP header setting. Setting the HTTP headers is the recommended method, because:

Some browsers do not treat the <META> tags in the same way as the equivalent HTTP header settings.
On some browsers, the <META> tag equivalents do not work when the callPage() method is used to load a JSP file that contains the <META> tags.
There may be instances in when you want to permit a page to be cached, but you do not want the proxy server to permit multiple users to have access to the cached page. For example, suppose your servlet does not use session tracking and it generates a Web page that contains user input. To maintain that personalization, you would want to prevent other users from having access to the cached page. To prevent the proxy server from sharing cached pages, use the following code:

<%
response.setHeader("Cache-Control", "private");
%>
This header can be combined with the three recommended headers for preventing caching

Flat View: This topic has 1 reply on 1 page
Topic: How to Extract Intra Day Stock Price Data from Java Chart. Previous Topic   Next Topic Topic: Downloading Files from the Internet

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use