Form form Action Submit problem detailed

Source: Internet
Author: User
Tags commit

Invalid parameter in form commit action


The page has two forms when it wants the server to submit data through the form, one is post and the other is get. One difference between the two is that get will append the data directly to the URL, and the data sent by post is placed in the HTTP packet. The Action property of the form is the URL address of the data being submitted, and the method property can specify either get or post.

Note that if you use Get method, then the parameters in the action URL are discarded, the submission will only be in the form of the data stitching at the URL to submit to the server, but the post is not the way, it will be specified by the action URL to submit data, Contains the parameters and parameter values followed by the URL


Action Commit path problem

I encountered a problem with form submission to Servelet processing:
(1) <form name= "Form1" action= "①"? "Method=" ②? ">
The contents of the form
</form>

(2) The corresponding servlet class for processing user requests is Helloservlet.java;


(3) Configure Web.xml files:

The code is as follows Copy Code

<servlet>
<servlet-name>③servlet</servlet-name>
<servlet-class>/HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>③servlet</servlet-name>
<url-pattern>/①welcome</url-pattern>
</servlet-mapping>

And then in the login.jsp, it should be:

<form action= "①welcome" method= "②?" ">

In that case, login.jsp's URL is http://localhost:8080/jsp/login.jsp.

And Helloservlet.java's URL is http://localhost:8080/jsp/welcome.

Note: The corresponding two servlet-name in the web.xml should be consistent, and url-pattern in ① should be consistent with the value of the Action property in the form forms.


Form form Action repeat submit


In doing a JSP submission page, the data inexplicably submitted 2 times, the database data inserted 2 times, began only to focus on the servlet, did a lot of testing, toss half-day, just test out: is not a servlet problem! The problem is on the JSP page. The submission event for the JSP page resulted in automatic submission 2 times.
The JS judgment function for form form only returns false, forgetting to write back true, really depressing death. Just like the following:

The code is as follows Copy Code
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 repeatedly submitted 2 times due to a missing return true.
To search, many people on the Web encounter the form form action repeatedly submitted 2 times, the reasons are similar:
As follows
1.

The code is as follows Copy Code
(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 page Some link address is ""
Such as:

The code is as follows Copy Code

<link type= "text/css" href= "/>" rel= "stylesheet"/>

The main thing is that the connection cannot be empty.
3.
Recently doing a Java project, found in the landing page after clicking on the code to execute 2 action, followed by 2 days to finally find the root cause of the problem:
In the landing page login.jsp, if the Submit button is written in the following manner, it will be submitted two times:

  code is as follows copy code

<script Type= "Text/javascript"
Function Loginfunc ()
{
var form = document.getElementById ("Form1");
 & nbsp 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 ()"/>//The problem is in this line
</form>

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

Solution Method:

The code is as follows Copy Code
<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.