Problems caused by Internet Explorer cache

Source: Internet
Author: User

I used struts's multi-language function to write something and used the locale object. (I will not talk about how to do it. I don't want to talk about struts here ).
There is no problem in the local test, and the switch between Chinese and English is OK. Put it on the remote server and try again. However, some people continue to reflect that sometimes it is strange to click the link in the English page environment and then return to the Chinese page environment! My first response was definitely a cache problem. Then, carefully check the html <meta> tag of all jsp pages to ensure that all no cache and expire attributes are set. Then we asked everyone to set the IE check attribute to "each check ". I have clicked on my machine for countless times. It seems that there is no problem in switching between Chinese and English. But it wasn't long before someone complained about the problem again.
Here we will introduce a tool called httpwatch, which is an embedded IE tool used to detect all HTTP Communication of IE. Without this tool, it is very difficult for me to find the problem (of course, it may be a good man who knows, but everyone has to go through the unknown process ).
The jsp page uses the following link to call struts action to switch the language environment. http: // localhost/xxx/langAction. do? Lang = 'zh '. However, the link is cached by IE, which means that the server does not receive the request in many cases. The solution can be to add a random number or timestamp behind the link. The problem is that many of these links have hardcode in flash (modify the flash code? ), So this method does not work. Interestingly, if this action only modifies the locale attribute in the session and does not notify the front controller to return the result page to the user (that is, return null ), this will certainly be cached. However, if you want to return a page to the user, the cache frequency will be much lower.
Finally, we infer that the problem lies in two places.
1. the cache of IE may be stored and determined by using url link + page result, rather than sending a request. In the case of return null, the judgment is based on url link + null.
2. On jsp pages, you cannot disable caching by using html <meta> tags. Be sure to add
Response. setHeader ("Pragma", "No-cache ");
Response. setHeader ("Cache-Control", "no-cache ");
Response. setDateHeader ("Expires", 0 );
Some people will say that this is not the same as html tag settings. Indeed, I also think that, but practice has proved that, without these few sentences, html tags alone are not acceptable.
Therefore, when an action returns a page, the following two conditions exist:
A. the returned page does not contain the statements that prohibit the cache (or only the html tag is written ). IE stores URL link + page result (cache eabled ). This is why cache exists.
B. The returned page contains the cache ban statement. IE stores URL link + page result (cache disabled ). In this way, we can achieve what we want. Each time a request is actually sent.
PS: I can't believe all the settings of IE check. Even though it is adjusted to the highest level, it will be cached if the above measures are not taken. Besides, you cannot tell users all over the world to modify Internet Explorer to view your website. (Not tested in other browsers)

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.