Summary: JSP page img Image caching problem expression and problem solving __jsp

Source: Internet
Author: User

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.

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.