hi everyone ,Can any one tell me how to prevent caching an image in broser .when i first user logs in the out.gif is stored in cache & second user is also getting same image . thanks in advance
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35254
7
posted
0
One way is to append a timestamp or unique ID to the image URL, like "...image.jpg?id=8912763482763487264".
The proper way would be to set correct caching response headers when serving the image, so that the browser knows not to cache it.
As the servlet is forwarding request to jsp ,i am unable to see wheather jsp is expired or not ,but mainly the image is not expired (indicating None)
thanks in advance nikki
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35254
7
posted
0
The headers in the JSP control the caching of the HTML page generated by the JSP, not the caching of any images it references. You need to set those headers for the image. That may mean that you need to address images through a servlet, which streams it to the browser and can set headers at will.
but no change same image in cache is displayed .Can you send me a piece of code how to address image from servlet .thanks in advance
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35254
7
posted
0
Nothing you do in the JSP is going to affect the images - it will affect the caching of the HTML page.
The CodeBarn has an example of how to stream images from a servlet. I'm not sure if it sets headers, have a look at its source. You'll need to pass the name of the image as URL parameter to the servlet, so that the servlet can read the file from disk.
Originally posted by Ulf Dittmer: The CodeBarn has an example of how to stream images from a servlet. I'm not sure if it sets headers, have a look at its source. You'll need to pass the name of the image as URL parameter to the servlet, so that the servlet can read the file from disk.
It does set headers (but not no-cache headers). It's not necessary to pass the image name as a parameter. The servlet is mapped to "/images/*" and the servlet parses the image name from the URL. [ February 18, 2008: Message edited by: Ben Souther ]