STRUTS2 itself provides a duplicate-submit check mechanism, but I don't want to pop up an error page, but instead do nothing, just commit once
1. Set a variable, set a variable, only allowed to submit once.
<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. How to disable a button
Because our server is too slow, let the button dimmed, give 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">
Disabling immediately causes the button's individual action setting to expire, so add a delay
Method 2 is effective in IE6. Firefox is not valid for unknown reason. But it's the second insurance anyway, it doesn't matter.