how to clear browser cache programmatically in jsp?

后端 未结 5 2225
情歌与酒
情歌与酒 2020-12-09 13:20

In my web application there is some problem due to browser cache.

How to clear the browser cache when loading my jsp page?

How can i include clear cache code

相关标签:
5条回答
  • 2020-12-09 13:57

    The same effect can be achieved by using meta tags in the HTML header:

    <meta http-equiv="Pragma" content="no-cache"> 
     <meta http-equiv="Cache-Control"      content="no-cache"> 
    <meta http-equiv="Expires" content="Sat, 01 Dec 2012 00:00:00 GMT">
    

    The Cache-Control header was added in HTTP 1.1, while the other two were also present in HTTP 1.0.

    0 讨论(0)
  • 2020-12-09 14:04

    You can do this way in your JSP to prevent from caching,not able to clear the cache programatically:

     <% response.setHeader("Cache-Control","no-cache"); //HTTP 1.1 
     response.setHeader("Pragma","no-cache"); //HTTP 1.0 
     response.setDateHeader ("Expires", 0); //prevents caching at the proxy server  
    %>
    
    0 讨论(0)
  • 2020-12-09 14:10

    How to disable browser caching for a specific JSP? It is possible to keep the browser from caching a JSP page response. The following hints added to the response header seem to prevent most modern browsers from pulling pages out of cache when the same URL is "hit":

    <%
       response.setHeader( "Pragma", "no-cache" );
       response.setHeader( "Cache-Control", "no-cache" );
       response.setDateHeader( "Expires", 0 );
    %>
    

    The same effect can be achieved by using meta tags in the HTML header:

    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT">
    
    0 讨论(0)
  • 2020-12-09 14:14
    <%
    response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
    response.addHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    %>
    

    This worked for me. Reference

    0 讨论(0)
  • 2020-12-09 14:19
     <%
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
     %>
    

    work perfect in jsp and remember to check session

    <%
    
    User u = (User) request.getSession().getAttribute("user");
    if (u != null ) {
    //show page
    }else{
    // redirect to login page
    }
    
    %>
    
    0 讨论(0)
提交回复
热议问题