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 ()"/>