esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

How do I prevent the browser from caching the output of my servlet?
Setting "pragma: No-Cache" in servlet response should help:

 
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
// blah-blah...
resp.addHeader("pragma", "No-Cache");
//.. here goes output
}


But some broken web browsers (IE in particular) do not always honor this header. So a brute force approach may do: add to every URL you need non-cached some random parameter that your code will ignore. That is, if you have URL 'http://myhost/myservlet/param=1', turn it into something like 'http://myhost/myservlet/param=1&anticache=876348763458' and generate random values for 'anticache' parameter. This is known to work when IE tends to cache output which it should not.


Further Information
Author of answer: hal9000

Comments
Comments to this answer are only viewable by members. Login or become a member!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.