Original from:
Http://blog.sina.com.cn/s/blog_693d183d0100uolj.html
Submit is a special case of the button and a button, which automatically integrates the commit action.
If the form after the click on the Submit button need to use JS processing (including input validation) and then submit, usually must be changed to button, that is, to cancel its automatic submission behavior, otherwise, will result in two times the effect, for Dynamic Web page, that is, the database operation two times. Or, add return True or False when validating with submit.
The Submit and button, both of which are displayed as buttons, appear to be buttons, different from the type attribute and the event where the response is sent, and submit the form, and the button does not submit the form.
The main difference between the two is:
Submit by default to form submission, you can submit a form (form).
The button responds to a user-defined event and does nothing if it does not specify an event handler such as the onclick. Of course, a button can also complete the work of a form submission.
INPUT type=submit Send form, press ENTER to submit form
INPUT Type=button is simply a button function, submitted by innertext
Detailed comparison of ===============submit and buttons ===================================
Submit: Special button, will automatically submit the form data, the OnClick method does not add return will be automatically submitted, does not play the role of constraints,
Therefore, the use of submit requires validation, return TRUE or false.
Example: <input type= "Submit" name= "submit" value= "register" onclick= "return check ();" In JS, write return True when judging. or return false;
Button: Normal buttons do not automatically submit form data. Can be explicitly submitted in JS: Document.form1.submit (), Use occasions: a page has more than one submit button, according to the user's actions to determine exactly which controller to submit, in this case, It is necessary to determine the user's operation in JS, and then according to the operation to assign a value to Document.form1.action and Document.form1.submit () to submit
=============== If you want all the submissions to be handled in a servlet, what to do ==================
The submitted button is also an HTML component, so it can also be obtained by GetParameter (), so the parameters of the GetParameter () also need to be fixed.
The parameter is the name of the Submit button for all forms, of course the name of the Submit button is the same as to unify the operation in a servlet based on the value of the Submit button
====================== about the path settings ===================================
A. Write the path directly in the page, such as href= "jsp/a.html" for the peer directory access, this example indicates that there is a JSP folder in the peer directory, access to the a.html file in the folder
B. A direct write path in Java, such as Response.sendredirect ("jsp/a.jsp"), indicates that there is a JSP folder under the project root directory, access to the a.jsp file in the folder
C. If you find that the above settings in the browser address bar is incorrect, you can take an absolute path to the wording:/project name/folder name/file name
But for the Web UI people should be aware that using submit to improve the usability of the page:
After using submit, the page supports keyboard enter operations, while many web software designers may not notice the submit unification.
The page does not support the ENTER key after the button is used. Therefore, you need to support the ENTER key, you must set a submit, the default enter key to the first submit to the page operation.
<input type= "Submit" Name= "B1" value= "Submit" onclick= "Bt_submit_onclick ()" >
After executing the onclick, go to action. Can be automatically submitted without the onclick, so that onclick here can not.
<input type= "button" Name= "B1" value= "Submit" onclick= "Bt_submit_onclick ()" >
After executing the onclick, jump file in the JS file control, submit the need for onclick. If there's no onclick here,
For example:
Type= "Submit"
<form id= "Frm1" action= "<%=request. ServerVariables ("Script_name")%> "method=" POST "onsubmit=" return Check_submit (This) ">
<input id= "btnconfirm" type= "Submit" value= "OK" name= "btnconfirm" ></form>
Type= "button"
<form id= "Frmaddmodi" action= "<%=request. ServerVariables ("Script_name")%> "method=" post "name=" Frmaddmodi ">
<input id= "btnconfirm" type= "button" value= "OK" name= "btnconfirm" onclick= "Check (Frmaddmodi);" /></form>
button and submit