Tell the browser to not cache the image. Set the following headers on the servlet response before the first bit is ever written to its body:
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.
To prevent hard-nosed browsers from still caching it, add a request parameter with a timestampto the servlet URL.
<h:graphicImage value="imageServlet?id=#{bean.imageId}&t=#{now.time}" />
Where #{now}
is been registered in faces-config.xml
as follows:
<managed-bean>
<managed-bean-name>now</managed-bean-name>
<managed-bean-class>java.util.Date</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…