The method of preventing the Java Web browser from caching the current web page
The so-called browser cache means that when you visit a web page for the first time, the browser will cache these web pages locally. The next time you visit these cached web pages, the browser will directly read the contents of these web pages from the local without getting them from the network.
Although the caching function provided by the browser can effectively improve the loading speed of web pages, for some web pages that need to be updated in real time, this caching mechanism will affect the normal display of web pages. Fortunately, three fields are provided in the HTTP response header to turn off the caching function of the client browser. The following three statements use these three fields to close the browser cache:
Although the above three HTTP response header fields can turn off the browser cache. However, not all browsers support these three response header fields. Therefore, it is best to use the above three response header fields at the same time to close the browser cache.
Example: disable the browser from caching the current web page
1. Example description
This program demonstrates the performance of submitting a request message through the form without closing the browser cache and closing the browser cache.
2. Write cache class
In the cache class, use the above three response header fields at the same time to close the browser cache and output a segment of @ r to the client_ 301_ 1457 @ to test the effect of closing cache and not closing cache. The implementation code of cache class is as follows:
As can be seen from the above code, when the cache request parameter value is false, close the browser's cache.
3. Configure cache class
The configuration code of cache class is as follows:
4. Test that the browser cache is not closed
Enter the following URL in the browser address bar:
http://localhost:8080/demo/Cache?cache=true
http://localhost:8080/demo/Cache?cache=false