Struts2 itself provides a checking mechanism for repeated submissions, but what I want is not to pop up an error page, but to treat it as nothing happened and only perform one submission
. 1. Set a variable, set a variable, and only allow one submission.
<script type="text/javascript">
function checkSubmit() {
if (checkSubmitFlg == true) {
return false;
}
checkSubmitFlg = true;
return true;
}
</script>
<form onsubmit="return checkSubmit();" method="post">
Method 1 is effective on IE6 and FIREFOX
. 2. Disable the button. Because our server is too slow, the button becomes Gray, giving users a better experience
<script type="text/javascript">
function disableSubmit(form) {
var elements = form.elements;
for (var i = 0; i < elements.length; i++) {
if (elements[i].type == 'submit') {
elements[i].disabled = true;
}
}
}
</script>
<form name="form1" onsubmit="setTimeout('disableSubmit(form1)',100) return checkSubmit();" method="post">
If you disable it immediately, the individual action settings of the button will become invalid, so Method 2 to add a delay is valid in IE6. Invalid on FIREFOX, reason unknown. But it’s the second insurance anyway, so it doesn’t matter.
Reference article
http://blog.csdn.net/LoveYou1999/archive/2007/02/02/1501295.aspx
http://www.takka.com.hk/jstutor/ch10/ch10.htm