日期:2014-05-18  浏览次数:20609 次

刷新页面为何会自动拷贝一条记录????
刷新页面为何会无缘无故的自动拷贝一条记录?
刷新时浏览器有个提示如下
The   page   cannot   be   refreshed   without   resending   the   infoemation.
Click   Retry   to   send   the   information   again,
or   Click   Cancel   to   return   to   the   page   that   you   were   trying   to   view
点retry就多了一条记录?这是怎么回事?怎么修改?

------解决方案--------------------
刷新时 上次发送的请求被重新发送了 而上次发送的请求就是生成一条记录
所以刷新后又会生成一条记录
------解决方案--------------------
设置一个变量,只允许提交一次。
<script language= "javascript ">
var checkSubmitFlg = false;
function checkSubmit() {
if (checkSubmitFlg == true) {
return false;
}
checkSubmitFlg = true;
return true;
}
document.ondblclick = function docondblclick() {
window.event.returnValue = false;
}
document.onclick = function doconclick() {
if (checkSubmitFlg) {
window.event.returnValue = false;
}
}
</script>
<html:form action= "myAction.do " method= "post " onsubmit= "return checkSubmit(); ">

------解决方案--------------------
解决方法1:使用struts中token技术
解决方法2:在提交表单,插入数据以后,使用redirect跳转