說明存在三個jsp頁面page1,page2,page3
通過page1查詢得到page2頁面,通過page2頁面的連結得到page3頁面
現在要後退,當在page3後退的時候,要把page2中的下面指令碼刪掉,否則就會報頁面已經到期
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
%>
2007-5-31 15:24 hope822
在JSP頁面中,點後退按鈕時,顯示頁面到期或操作逾時之類的錯誤,如何做
我是用java開發的網站,資料庫用的是mysql,請問,在JSP頁面中,點後退按鈕時,顯示頁面到期或操作逾時之類的錯誤 ,
總之顯示不出頁面內容,不能回到之前的頁面繼續操作了,這樣的效果是怎麼做出來的?
請高手指點,最好有代碼,謝謝!
2007-5-31 16:07 賽揚
在之前的頁面頂端寫
<%
//禁止緩衝
response.setHeader("Catch-Control","no-store");
response.setHeader("Pramga","no-catch");
response.setDateHeader("Expires",0);
%>
2007-5-31 16:23 hope822
回複 #2 賽揚 的文章
多謝,我晚上回去試一下!;-)
2007-5-31 22:40 hope822
回複 #2 賽揚 的文章
我試了,可是沒成功!
我再說一下我要的功能:
我現在是通過背景登陸介面進入後台,當點“退出”時,退出到後台登陸介面。此時,我再點IE瀏覽器上的後退按鈕時,卻仍能進入後台,繼續進行操作,這當然不是我們所希望得到的效果。
請問, 在退出後,如何限制“後退”之後就不能再進入後台頁面了,只能再登陸才能進去!
如果還是你說的這段代碼的話,能否再請詳細說一下代碼置放位置,我把它放在html外,head裡,body裡,這幾個地方都試了,好像都沒有達到效果,還請再指點一下;如果不是,請再說一種方法,謝謝!
2007-5-31 23:40 SinNeR
之前你沒說清楚,讓賽揚理解錯了。
通過session來控制。
使用者登陸時,在session中寫入使用者資訊,退出的時候清空session。
這樣在操作頁面通過判斷session就可以知道當前的使用者是否合法。
2007-6-1 08:43 賽揚
接SinNeR:
比如在登入表單提交後的頁面,寫入
<%
session.setAttribute("admin","1");//向session發送字串變數admin,值為"1"
%>
然後通過連結或response.sendRedirect("....要轉向到的頁面名稱....");轉向到你的背景程式頁面
在背景程式頁面寫入
<%
String admin = (String)session.getAttribute("admin");
if(admin!=null){
//在這裡正常顯示登入後應顯示的內容
}else{
//這裡就要報錯了,未登入或已逾時,顯示提示資訊然後N秒後自動轉向到登入頁面
}
%>
2007-6-1 14:12 hope822
回複 #6 賽揚 的文章
謝謝啊
問題解決了。
這樣點後退就會顯示頁面已到期。
但怎麼能使那個後退的記憶功能沒有啊!就是不能點那個後退鍵啊!
謝謝啊!
2007-6-1 14:15 hope822
回複 #6 賽揚 的文章
這種方式應該是這樣解決!
<%
//禁止緩衝
response.setHeader("Catch-Control","no-store");
response.setHeader("Pramga","no-catch");
response.setDateHeader("Expires",0);
%>
但我用了沒起作用!
是不是我放的地方不對,還是什麼問題?
2007-6-1 15:54 賽揚
用禁止緩衝配合session即可
以下兩篇貼子供你參考
[url]http://bbs.blueidea.com/thread-701496-1-1.html[/url]
[url]http://bbs.blueidea.com/thread-1556412-1-1.html[/url]
2007-6-1 21:21 hope822
回複 #9 賽揚 的文章
現在知道用禁止緩衝配合session可以做到。
我在退出時把success設定為2。
<c:if test="${success == 2}">
<div class="chaoshi">
<h1> 您已沒有許可權,請返回重新登陸! </h1>
<a href="<%=request.getContextPath()%>/admin/index.jsp">返回,請點這裡</a>
</div>
但我用禁止緩衝的代碼並沒起作用?
<%
//禁止緩衝
response.setHeader("Catch-Control","no-store");
response.setHeader("Pramga","no-catch");
response.setDateHeader("Expires",0);
%>
現在是點後退之後還可以看到頁面的顯示,只有點頁面的按鈕之後才出現
您已沒有許可權,請返回重新登陸!
我哪弄錯了?謝了啊!
2007-6-2 12:51 hope822
還請再次指點一下,在此先謝過拉!
2007-6-2 13:18 asp910
你那些是在伺服器端執行的,後退時是沒有向伺服器請求的
看到的頁面可能是瀏覽器之前緩衝在Temporary Internet Files目錄下的
清理一下緩衝測試一下
另外session許可權判斷最好放在Filter下,然後配置過濾的url,這樣方便一些
<%@page contentType="text/html;charset=gb2312" language="java"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@page import="com.fsti.doms.core.model.DOMSGlobalConstant" %>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
%>
<html>
<head><html:base/>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<link href="../css/style.css" type="text/css" rel="stylesheet">
<script src="../js/public.js" language="javascript"></script>
<script language="javascript" src="../js/checkAll.js"></script>
<script language="javascript" src="../js/calendar.js"></script>
<script src='<%=request.getContextPath()%>/dwr/engine.js'></script>
<script src='<%=request.getContextPath()%>/dwr/util.js'></script>
<script src='<%=request.getContextPath()%>/dwr/interface/StaffService.js'></script>
<script src="../js/DWRUtil.js" language="javascript"></script>
<style>
body,table,td{
font-size:12px;
}
</style>
<script language="javaScript">
function showDiv()
{
document.all.mydiv.style.display="none";
}
function time_delay()
{
setTimeout("showDiv();",10000);
}
function searchStaff(){
var o = window.event.srcElement.parentElement.parentElement;
window.document.all.rowNum1.value = o.rowIndex;
window.document.all.cellNum.value = window.event.srcElement.parentElement.cellIndex;
window.open('simpleStaffSearch.jsp','','scrollbars=yes,resizable=yes,width=600,height=450,left=50,top=100');
}
function checkData(){
if(check('c2')){
if(document.all.item.value == ""){
alert("請選擇項目編號!");
return false;
}
if(confirm("料單可能需要重新列印,是否確定批量項目修改?")) {
document.all.refer.value='正在操作,請稍候...';
document.all.refer.disabled=true;
document.theForm.submit()
}}
else{
alert('請選擇要項目資訊修改的料單!')
}
}
function init(){
var now = new Date();
var year = now.getYear();
var month = now.getMonth() + 1;
var date = now.getDate();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
CurrentTime = "";
CurrentTime += year + "-";
CurrentTime += month + "-";
CurrentTime += date ;
CurrentTime +=" ";
sT=CurrentTime;
if(document.theForm)
document.theForm.operDate.value=sT;
}
</script>
</head>
<body onkeydown="shieldKey()"oncontextmenu="rightKey();" topmargin="0" marginheight="0" leftmargin="0" marginwidth="0" onLoad="init();time_delay()">
<table width="100%" border="0" cellpadding="0" cellspacing="0" height="25">
<tr><td class="titlebar1">項目資訊更改列表</td></tr>
<logic:notPresent name="resultBillList" scope="request">
<tr><td class="tipbar3">查無資料</td></tr>
</logic:notPresent>
</table>
<br/>
<div style="display:block;" id="mydiv">
<logic:present name="allsucc" scope="request">
<p class="tipbar3">批量項目資訊更改成功!</p>
</logic:present>
<logic:present name="succ" scope="request">
<p class="tipbar3">料單操作成功!</p>
</logic:present>
</div>
<logic:present name="resultBillList" scope="request">
<form action="batchModifyItemForBillAction.do" method="get" name="theForm">
<table id="result" class="tablecolor1" cellspacing="0" cellpadding="3" width="100%" align="center">
<tbody>
<tr>
<th nowrap width="3%"><input type="checkbox" name="c2all" onClick="CheckAll('c2','c2all')">全選</th>
<th nowrap width="3%">序號</th>
<th align="center" width="15%" nowrap>申請單編號</th>
<th align="center" width="15%" nowrap>正式單編號</th>
<th align="center" width="17%" nowrap>申請單開單時間</th>
<th align="center" width="8%" nowrap>申請人</th>
<th align="center" width="15%" nowrap>項目編號</th>
<th align="center" width="15%" nowrap>項目名稱</th>
<th align="center" width="15%" nowrap>工程隊名稱</th>
<th align="center" width="12%" nowrap>總金額</th>
<th align="center" width="15%" nowrap>料單狀態</th>
</tr>
<logic:iterate id="item" name="resultBillList" scope="request" indexId="index">
<tr onmouseover=setCol1(this) onmouseout=setCol2(this)>
<td align="center"><input type="checkbox" name="c2" value="<bean:write name="item" property="billId"/>"></td>
<td align="center" nowrap><font color="red"><%=index.intValue()+1%></font></td>
<td align="center" nowrap><a href="toShowBillForItemModifyAction.do?billId=<bean:write name="item" property="billId"/>&billType=<bean:write name="billType"/>"><bean:write name="item" property="applyCode"/></a></td>
<td align="center" nowrap><a href="toShowBillForItemModifyAction.do?billId=<bean:write name="item" property="billId"/>&billType=<bean:write name="billType"/>"><bean:write name="item" property="billCode"/></a></td>
<td align="center" nowrap><a href="toShowBillForItemModifyAction.do?billId=<bean:write name="item" property="billId"/>&billType=<bean:write name="billType"/>"><bean:write name="item" property="applyDate"/></a></td>
<td align="center" nowrap><a href="toShowBillForItemModifyAction.do?billId=<bean:write name="item" property="billId"/>&billType=<bean:write name="billType"/>"><bean:write name="item" property="materialMan.staffName"/></a></td>
<td align="center" nowrap><a href="toShowBillForItemModifyAction.do?billId=<bean:write name="item" property="billId"/>&billType=<bean:write name="billType"/>">
<logic:notEmpty name="item" property="item">
<bean:write name="item" property="item.itemCode"/>
</logic:notEmpty>
</a></td>
<td align="center" nowrap><a href="toShowBillForItemModifyAction.do?billId=<bean:write name="item" property="billId"/>&billType=<bean:write name="billType"/>">
<logic:notEmpty name="item" property="item">
<bean:write name="item" property="item.itemName"/>
</logic:notEmpty>
</a></td>
<td align="center" nowrap><a href="toShowBillForItemModifyAction.do?billId=<bean:write name="item" property="billId"/>&billType=<bean:write name="billType"/>">
<logic:notEmpty name="item" property="engineer">
<bean:write name="item" property="engineer.engineerName"/>
</logic:notEmpty>
</a></td>
<!--
<td align="center" nowrap><a href="toShowBillForItemModifyAction.do?billId=<bean:write name="item" property="billId"/>&billType=<bean:write name="billType"/>">
<logic:equal name="movebill" value="movebill">
<logic:notEmpty name="item" property="outStoreHouse">
<bean:write name="item" property="outStoreHouse.storeHouseName"/>
</logic:notEmpty>
</logic:equal>
<logic:notEmpty name="item" property="storeHouse">
<bean:write name="item" property="storeHouse.storeHouseName"/>
</logic:notEmpty></a></td>
-->
<td align="center" nowrap><a href="toShowBillForItemModifyAction.do?billId=<bean:write name="item" property="billId"/>&billType=<bean:write name="billType"/>">
<script language="javaScript">
document.write(formatFloat(<bean:write name="item" property="sum"/>,2));
</script>
</a></td>
<td align="center" nowrap><a href="toShowBillForItemModifyAction.do?billId=<bean:write name="item" property="billId"/>&billType=<bean:write name="billType"/>"><bean:write name="item" property="currentStatus.statusName"/></td>
</tr>
</logic:iterate>
</tbody>
</table>
<table id="billTable" class="tablecolor1" cellspacing="0" cellpadding="3" width="100%" align="center">
<tr>
<td align="right" nowrap>項目編號:</td>
<td nowrap>
<input type="hidden" name="item" value="">
<input type="text" name="itemCode" value="" readonly size="30">
<input type="button" class=sBtn1 value="..." onClick="window.open('itemSearch.jsp','','scrollbars=yes,resizable=yes,width=800,height=500,left=50,top=100')"/><font class='red'> * </font></td>
<td align="right" nowrap>項目名稱:</td>
<td><input type="text" name="itmeName" value="" size="40" readonly size="30"></td>
</tr>
<tr>
<td align="right" nowrap>專案經理:</td>
<td nowrap>
<input type="hidden" name="itemManager" value="">
<input type="text" readonly name="itemManagerName" value="" size="30">
<input type="button" class=sBtn1 value="..." onClick="searchStaff();" style='cursor:hand'/></td>
</tr>
</table>
<p style="margin-left:20px;"> <input name="operDate" type="text" size="15" onfocus="calendar()">
<input type="button" class=btn1 name="refer" value="批量項目更改" onClick="checkData();"></p>
<input type="hidden" name="billType" value="<bean:write name="billType"/>">
<input type="hidden" name="billTypeId" value="" />
</form>
</logic:present>
<br/>
<input type="hidden" name="rowNum" value="" />
<input type="hidden" name="rowNum1" value="" />
<input type="hidden" name="cellNum" value="" />
</body>
</html>