Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java servlet how to disable caching of page

Tags:

java

servlets

How to disable caching ?

What headers should doGet set?

Could you provide a code snippet?

like image 844
EugeneP Avatar asked Oct 20 '10 09:10

EugeneP


People also ask

How do I stop page caching?

When you're in Google Chrome, click on View, then select Developer, then Developer Tools. Alternatively, you can right click on a page in Chrome, then click Inspect. Click on the Network tab, then check the box to Disable cache.

What provides control over caching?

The Cache-Control HTTP header field holds directives (instructions) — in both requests and responses — that control caching in browsers and shared caches (e.g. Proxies, CDNs).


1 Answers

This will set caching to disabled on the response:

// Set standard HTTP/1.1 no-cache headers.
response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");

// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");
like image 114
rsp Avatar answered Sep 30 '22 17:09

rsp