Prevent duplicate submissions in JSP

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.