Form form action Repeat submit 2 times

Source: Internet
Author: User

          when making a JSP submission page, the data was inexplicably submitted 2 times, the database data was inserted 2 times, and began to focus only on submitting to the servlet, doing a lot of testing, tossing half a day, Just test it out: It's not a servlet problem at all. The problem is on the JSP page. The submission event for the JSP page resulted in automatic submission 2 times. The
Form form's JS judgment function returns false only, forgetting to write back true, which is depressing death. Just like this:
function check ()
{
if ("==document.myform.name.value)
{//Job name
Window.alert (" Please fill in the job name first.) ");
Document.myform.name.focus ();
$ (". Name"). Next (). Show ();
return false;//Leave function
}
}
Submit Button onclick= "Javascript:return (Checkform ());" The
Check () function above causes the form form action to be repeated 2 times due to missing return true.
Search for a lot of people on the Web encounter the form form action repeatedly submitted 2 times the problem, the reasons are similar:
as follows
1.
(1) <input type= "Submit" value= "Tijiao" onclick= "return CheckField ();" /> or picture <input type= "image" src= ". /images/btn-login.gif "alt=" Login "class=" Btn-login "onclick=" return CheckField (); />
(2) if (Usernamevalue!== "" && passwordvalue!== "") {

//document.getelementbyid ("LoginForm"). Submit (); If you write this line, you submit it 2 times.
return true;
}

2.jsp pages Some link addresses are ""
such as:

<link type= "text/css" href= ""/> "rel=" stylesheet "/> The primary
is that the connection cannot be empty.
3.
recently in a Java project, found in the landing page after clicking on the code to perform 2 action, tracking 2 days finally found the source of the problem:
in the landing page login.jsp, if the submit button written as follows will be submitted two times:
<script type= "Text/javascript"
Function Loginfunc ()
{
var form = document.getElementById ("Form1 ");
Form.submit ();
}
</script>



<form action= "processlogin.action" method= "Post" id= "Form1"
<s:textfield name= "username" cssclass= "input" style= width:150px; "value=" ></S:TEXTFIELD>
<s: Password name= "password" cssclass= "input" style= "width:150px" "value=" ></S:PASSWORD>
<input type= " Submit "onclick=" Loginsystem () "/>//problem occurs in this row
</form>

Submit type itself is committed to the action class The OnClick method also invokes a submit Submit method, which results in the execution of the code with the action two times.

Workaround:
<input type= "button" onclick= "Loginsystem ()"/>

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.