Prevent servlet from caching,

V

vinodh

I am having problem with servlet caching. My Servlet keeps displaying
previously cached image instead of an updated image. I tried out the
following workarounds and was not successful.

1. Set the following Response headers

res.setDateHeader("Expires", 0);
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate,
post-
check=0, pre-check=0");
res.setHeader("Pragma", "no-cache");

2. Set HTML META TAG:

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="0">

Has anyone experienced a similar issue and can you share your
worarounds. I even tried setting DateHeader as follows but no luck.
res.setDateHeader("expires", System.currentTimeMillis()).
thanks in advace
vinodh
 
C

Chris

I am having problem with servlet caching. My Servlet keeps displaying
previously cached image instead of an updated image. I tried out the
following workarounds and was not successful.

This problem is really a headache, because it's controlled by the user's
browser, not your application. One reliable way to fix it is to change the
name of the image each time it's updated.

Hey, I just had another idea -- haven't tried it, though. Maybe you can add
a random parameter to the image.

<img src="myimage.gif?rand=<%=myrandomnumber%>">
 
A

Andrea Desole

This problem is really a headache, because it's controlled by the user's
browser, not your application. One reliable way to fix it is to change the
name of the image each time it's updated.
I would just like to change this one into "it's controlled by the user's
buggy browser"
 
J

Juha Laiho

(e-mail address removed) said:
I am having problem with servlet caching. My Servlet keeps displaying
previously cached image instead of an updated image. I tried out the
following workarounds and was not successful.

1. Set the following Response headers

res.setDateHeader("Expires", 0);
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate,
post-
check=0, pre-check=0");
res.setHeader("Pragma", "no-cache");

Below you talk about what you do to some HTML code -- apparently code
surrounding your image. Are these HTTP headers also for the below HTML?

Note that the image is served in a separate request from the surrounding
HTML, and if your problem is with caching the image, then no amount of
cache-prevention in the surrounding HTML will help -- you have to provide
the relevant headers (Last-Modified, Expires and Cache-Control) for the
_image_ HTTP request.

2. Set HTML META TAG:
[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top