I am developing Jsp struts application. I am generating dynamic jframe chart from my action servlet and save as an image in the webcontent folder.I am displaying the same image in JSP using img tag. But the dynamic image is not getting refreshed though i am refreshing the JSP page. The image file in the webcontent folder is getting reloaded, but Jsp is still showing the old file.
ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
Joined: Mar 13, 2012
Yes, but how to empty the cache of the web browser?
I tried this but it did not work:
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="Expires" content="0" />
That will affect the browser caching of the HTML page generated by the JSP. It won;t affect the caching of the image itself. When a HTML page contains an img tag, the browser makes an additional request to the server to get the image. The image itself will have it;s own headers that will control how long the browser will cache it
What you need to do is look into the configuration of your web application server. It will have some way of controlling the header by file type. usually, default configuration for images is to allow browser to cache since normally your images don;t change that often. There are ways to override this behavior. For example Tomcat has an ExpiresFilter. If you have a Apache Load balancer, you could set httpd.conf. If you are using IIS, I believe you can change properties of a folder (might be wrong here.. been a while)
Well, assuming you do really have the same problem, the solution would be to make sure that your "dynamic image" reports its last-modified date correctly. If you're using a servlet to display that image then override the getLastModified(HttpServletRequest) method in that servlet to return the time at which the image was created.