There are two ways to restrict the repeated submission of forms on the client:
First, set a flag variable in a javascript script to identify whether the form has been submitted. If yes, a dialog box is displayed, indicating "submit again ".
Type 2: After you click the submit button, set the submit button to the disabled status. In this way, you cannot submit the button again, and the client cannot submit the button again.
1. Create a ClientTest1.jsp file with the following code:
<% @ Page language = "java" contentType = "text/html; charset = Gb2312" PageEncoding = "GB2312" %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> <Html> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = Gb2312"> <Title> restrict repeated submission on the client </title> <Script language = "javascript" <! -- Define repeated submission flag variables --> Var repeatSubmitFlag = false; <! -- Repeated submission check function --> Function checkSubmit () { If (repeatSubmitFlag) <! -- If the flag is true, the page has been submitted. --> { Window. alert ('repeated submission is prohibited! '); Return false; } Else { RepeatSubmitFlag = true; Return true; } } </Script> </Head> <Body bcolor = "# ffffff"> <Form name = "form_client" action = "http://www.dlmu.edu.cn" onsubmit = "return checkSubmit ();"> <Input type = "checkbox" name = "check_1" checked = true/> Dalian Maritime University <Input type = "submit" name = "submitok"/> </Form> </Body> </Html> |
2. If the form is submitted repeatedly, an error prompt dialog box will pop up.
1. Create a ClientTest2.jsp file. The Code is as follows:
<% @ Page language = "java" contentType = "text/html; charset = GB2312" PageEncoding = "Gb2312" %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> <Html> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = Gb2312"> <Title> repeated submission of client restrictions-2 </title> </Head> <Body bgcolor = "# ffffff"> <Form name = "form_client" action = "http://www.dlmu.edu.cn" Onsubmit = "your temporary Doc ument. form_client.submitok.disabled = true; return true;"> <Input type = "checkbox" name = "check_1" checked = "true"/> Dalian Maritime University <Input type = "submit" name = "submitok"/> </Form> </Body> </Html> |
2. If the form is submitted repeatedly, an error prompt dialog box will pop up.