The description and solution of the problem of the JSP page IMG Image caching
L Problem Statement:
When the information of the customer service personnel containing the avatar is modified (including changes to the avatar information), the data modification interface is reopened, the text content is changed successfully, and the Avatar content is still displayed as the original head--the corresponding information in the database The field data has been successfully updated.
L Prerequisites:
Page cache cleanup processing in JSP pages:
<meta http-equiv= "Pragma" content= "No-cache"/>
<meta http-equiv= "Cache-control" content= "No-cache"/>
<meta http-equiv= "Expires" content= "0"/>
Of course, the bottom 3 lines of code function is the same as the top 3 lines, the page only write a
<%
Response.setheader ("Pragma", "No-cache");
Response.setheader ("Cache-control", "No-cache");
Response.setdateheader ("Expires", 0);
%>
L Problem Scenario reappearance:
Original JSP in the IMG src writing:
/servlet/customer/personpic?cspid=${cspid}" ></img>
The data interface to modify:
After modifying the data, enter the modified interface of this data again:
I found that although other text fields have been modified accordingly, the "Avatar" section does not modify the image specified for us (pictured below, the Avatar still appears as a "fork" shape)
Query the database, found the image in the database the corresponding BLOB field data has changed to the specified picture.
L Problem Solving (two steps):
(1) Modify servlet: Add a picture random number code in the servlet that reads the data
Random number of pictures
double randomnum = Math.random ();
Request.setattribute ("Randomnum", randomnum);
(2) Update foreground data modify JSP: Picture shows the img tag in src add "randomnum" parameter
/servlet/customer/personpic?cspid=${cspid}&randomnum=${randomnum}" > </img>
Reopen the same person's data modification interface--successfully display the picture you just updated ...
L Principle:
Because of the addition of random number parameters in the IMG src, multiple access to the image, the browser is considered to have access to a different picture path (or access to a different picture), the browser will again visit the server to read the picture, and no longer read the cached pictures.
Summary: If the above methods can not be solved, through the Java output stream directly to the foreground, similar to the generation of background verification code.
Related reference:
Solution to client image caching in JSP pages
http://damiao-cn.javaeye.com/blog/371216
JSP solves picture caching problem
http://wuaner.javaeye.com/blog/395443