Friday, June 13, 2014

JSP or Servlet pages cached by browser

In order to prevent the dynamic content output by JSP page from being cached by browser, we need to set few HTTP header attributes.Just execute the following scriptlet at the beginning of your JSP pages to prevent them from being cached at the browser. You need both the statements to take care of some of the older browser versions.

<% 
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma\","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>

No comments:

Post a Comment