重复提交

来源:互联网 发布:淘宝上的如新是真的吗 编辑:程序博客网 时间:2024/05/01 19:09

面对客户端我们可以使用Javascript脚本来解决,如下

1。重复刷新、重复提交
Ways One:设置一个变量,只允许提交一次。
<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();">

Way Two : 将提交按钮或者image置为disable
  <html:form action="myAction.do" method="post" 
    onsubmit="getElById('submitInput').disabled = true; return true;">  
  <html:image styleId="submitInput" src="images/ok_b.gif" border="0" />
  </html:form> 

2。防止用户后退
这里的方法是千姿百态,有的是更改浏览器的历史纪录的,比如使用window.history.forward()方法;有的是“用新页面的URL替换当前的历史纪录,这样浏览历史记录中就只有一个页面,后退按钮永远不会变为可用。”比如使用javascript:location.replace(this.href); event.returnValue=false;

原创粉丝点击