2012-12-17 46 views
2

我加入以下在jsp页面meta标签如何过期返回按钮点击页面?

<html> 
<head> 
<title>xyz</title> 
<link type='text/css' rel="stylesheet" href="sdsds/sdsd"/> 
<meta content="max-age=0" http-equiv="cache-control"> 
<meta content="no-store" http-equiv="cache-control"> 
<meta content="-1" http-equiv="expires"> 
<meta content="Tue, 01 Jan 1980 1:00:00 GMT" http-equiv="expires"> 
<meta content="no-cache" http-equiv="pragma"> 
</head> 
<body><h1>jsdsdsds</h1> 
<a href="abc">click me</a> 
</body> 
</html> 

通过点击链接导航后“点击我”我打开了新的一页。当我点击后退按钮它正在工作..我希望页面过期.. 注意:在这两个jsp页面我都添加了相同的元标记。 我尝试添加该

<%@ page import="java.lang.*" %> 
<% 
// Set to expire far in the past. 
response.setHeader("Expires", "Sat, 6 May 1971 12:00:00 GMT"); 
// Set standard HTTP/1.1 no-cache headers. 
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); 
// Set IE extended HTTP/1.1 no-cache headers (use addHeader). 
response.addHeader("Cache-Control", "post-check=0, pre-check=0"); 
// Set standard HTTP/1.0 no-cache header. 
response.setHeader("Pragma", "no-cache"); 
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server 
%> 

上述两种HTML和内部Head..still我可以看到背页, 在Mozilla Firefox 10.0测试,IE8 什么建议吗?

回答

0

你不能只要到期浏览器的后退按钮页面作为会话不是involved.Its那里回来浏览许多用户所做的页面,所以这取决于您希望用户如何浏览您的网站。您实际上需要处理浏览器的后退按钮。有几种方法可以做到这一点。 突出的一个是在JavaScript中使用此代码:`

window.history.forward(); 

` 但它会将您的回请求当前页面的历史 为我工作的一个是:

<script type="text/javascript"> 
function noBack(){ 
      location.replace(logouturl); 
      window.location="logouturl"; 
} 

HTML

<input type="button" value="SignOut" onclick="noBack()" align="middle"> 
+0

我创建了一个会话,然后在我的控制器中写下了代码。但它仍然不会过期页面。 'response.setHeader(“Cache-Control”,“no-cache,no-store”); response.setHeader(“Pragma”,“no-cache”); response.setHeader(“Expires”,“0”); response.setDateHeader(“Expires”,-1);'你能帮忙吗? – javafan

-1

试试这个

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> 
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> 
<META HTTP-EQUIV="EXPIRES" CONTENT="0"> 

Check this link它可能对你有帮助...

+0

不工作..同名bhevaiour – Rajesh

2

试试这个

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <title>Untitled Page</title> 
    <script type = "text/javascript" > 
    function changeHashOnLoad() { 
window.location.href += "#"; 
setTimeout("changeHashAgain()", "50"); 
} 

function changeHashAgain() { 
window.location.href += "1"; 
} 

var storedHash = window.location.hash; 
window.setInterval(function() { 
if (window.location.hash != storedHash) { 
    window.location.hash = storedHash; 
} 
}, 50); 


</script> 
</head> 
<body onload="changeHashOnLoad(); "> 
    Try to hit back! 
</body> 
</html>` 
+4

欢迎来到Stack Overflow!你会考虑增加一些叙述来解释为什么这段代码有效吗?是什么使它成为这个问题的答案? –