public static void setNoCache ( HttpServletRequest request , HttpServletResponse response ) { //get rid of unwanted whitespace String protocol = request . getProtocol ( ) . trim ( ) ; // if ("HTTP/1.0".equals(protocol)) { response . setHeader ( "Pragma" , "no-cache" ) ; } // else if ("HTTP/1.1".equals(protocol)) { response . setHeader ( "Cache-Control" , "no-cache, max-age=0, revalidate" ) ; //no-store only disables archiving } //get browser type // String userAgent = request.getHeader("User-Agent"); // if ((userAgent != null) && (userAgent.indexOf("MSIE") != -1)) { //Internet Explorer: //date and timestamp will be set to jan 1st 1970, so no caching is performed. // response.setDateHeader("Expires", 0); } long now = System . currentTimeMillis ( ) ; response . setDateHeader ( "Date" , now ) ; response . setDateHeader ( "Expires" , now ) ; response . setDateHeader ( "Last-Modified" , now ) ; }
Takes as many precautions as possible to prevent this page from being cached by the browser