What is page cache? Simply put, try the forward/backward button on IE or Firefox toolbar and you will know. that is to say, the browser will cache the page first. When it is used for the next time, it will retrieve data directly from the cache without re-retrieving data from the web server. this reduces the pressure on the server.
But there are disadvantages in everything. For example, how do I log out when logging on to a web page? Of course, the servlet can use session. removeattribute ("LOGNAME"); Session. invalidate (); however, this alone is not perfect. If the user does not close the browser in time, pressing the "back" button may cause an insecure factor (because the user does not actually exit ). Fortunately, the HTTP protocol can customize the cache page. Example:
Generally, the web page has a login button. Login button ing servlet or struts action and so on. That is to say, after the login action, it usually jumps to the home page. Therefore, add the clear cache code before the sendredirect or forward action:
Servlet Session. setattribute ("LOGNAME", LOGNAME); // The user writes the session </P> <p> // clear the page </P> <p> response. setheader ("Pragma", "No-Cache"); <br/> response. setheader ("cache-control", "No-Cache"); <br/> response. setheader ("cache-control", "No-store"); <br/> response. setdateheader ("expires", 0); </P> <p> // jump to the page </P> <p> requestdispatcher = NULL; <br/> requestdispatcher = request. getrequestdispatcher ("index. JSP "); <br/> requestdispatcher. forward (request, response); <br/>Struts2 Httpservletresponse response = servletactioncontext. getresponse (); <br/> // clear the cache on the login page <br/> response. setheader ("Pragma", "No-Cache"); <br/> response. setheader ("cache-control", "No-Cache"); <br/> response. setheader ("cache-control", "No-store"); <br/> response. setdateheader ("expires", 0); </P> <p> // page relocation, countdown. <Br/> string url = "index. JSP "; <br/> string content = 3 +"; url = "+ URL; // enter the home page 3 seconds later <br/> response. setheader ("refresh", content); </P> <p>In this way, when session. invalidate () is called, and then press IE or Firefox to exit, a prompt indicating that the page has expired will appear. Response. setheader ("refresh", content); implements countdown jump page