问题描述:

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 in jsp page?

网友答案:

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  
%>
网友答案:
 <%
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
}

%>
网友答案:

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.

相关阅读:
Top