How to stop a browser to cache a web page or ajax-response in java web appplications

In my recent web project, my pages were working well. But one of ajax call response was not working correctly. I figured out, the response I was getting was a cache copy returned by browser. If you are in same situation or wish the browser do not cache a particular web page or an ajax response. Here is the solution:

Just set "Cache-Control" header to "no-cache", in HttpServletResponse, like this:
response.setHeader("Cache-Control", "no-cache");


Popular posts from this blog

Task 12 - Create Java Program with MySQL Database Connectivity

Java Interfaces and Exception Handling - Practice Problem with Solution

Task 16 - Javafx Program to Create, Retrieve, Update and Delete records with Database