How to prevent caching in a JSP page?

Answered

How to prevent caching in a JSP page?

Ninja Asked on 18th September 2018 in Jsp.
Add Comment
1 Answer(s)
Best answer

Caching in JSP pages can be prevented by setting the appropriate HTTP header attributes.

The following scriptlet defined at the beginning of JSP pages can prevent them from being cached at the browser.

<%
 response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
 response.setHeader("Pragma","no-cache"); //HTTP 1.0</p>
 
 //prevents caching at the proxy server
 response.setDateHeader("Last-Modified", (new Date()).getTime() ); 
%>
Ninja Answered on 18th September 2018.
Add Comment