Button and submit, buttonsubmit
Original article from:
Http://blog.sina.com.cn/s/blog_693d183d0100uolj.html
Submit is a special case of a button and also a kind of button. It automatically integrates the submit action.
If the form needs to be processed (including input verification) by clicking the submit button and then submitted, you must change the submit to the button to cancel the automatic submission. Otherwise, it will result in two submissions. For dynamic web pages, that is, two database operations. Alternatively, return true or false is added for verification when submit is used.
Both submit and button are displayed in the form of buttons. They both look like buttons. what is different is that the type attribute and the event where the response is sent, the submit will submit the form, and the button will not submit the form.
The main differences between the two are:
By default, submit is used for form submission. You can submit a form (form ).
The button responds to user-defined events. If you do not specify event processing functions such as onclick, it does not do anything. Of course, the button can also complete form submission.
INPUT type = submit: Send the form. Press enter to submit the form.
INPUT type = button is a simple button function, and innerTEXT is submitted.
=================== Detailed comparison between submit and button ================================== ======================
Submit: A special button that automatically submits data in the form. The onClick method is automatically submitted without return, and does not apply constraints,
Therefore, you need to add return true or false for verification when using submit.
Example: <input type = "submit" name = "Submit" value = "register" onClick = "return check ();">, return true when determining in JS; or return false;
Button: A normal button. The data in the form is not automatically submitted. you can explicitly submit: document. form1.submit (): When a page has multiple submit buttons, you need to determine the Controller to which the page is submitted based on your operations. In this case, you need to judge the user's operations in JS, and then give the document according to the operation. form1.action value and document. form1.submit () to submit
================== If you want to handle all the commits in a servlet, how to Do This ============================
The submitted button is also an HTML component, so you can also get it through getParameter (), so the parameters of getParameter () need to be fixed.
The parameter is the name of the submit button for all forms. Of course, the name of the submit button must be the same so that it can be operated differently in a servlet based on the value of the submit button.
=================================== About the path settings ==================== ==================================
A. directly write the path on the page, for example, href = "jsp/a.html". In this example, A jspfolder is included in the Level directory, and the.html file in the folder is located.
B. write the path directly in JAVA, such as response. sendRedirect ("jsp/. jsp ") indicates that there is a JSP folder under the root directory of the project, accessing. jsp file
C. If you find that the address bar in the browser is incorrect, use the absolute path:/project name/folder name/file name.
However, people engaged in web ui should note that using submit to improve the ease of use of pages:
After submit is used, the page supports the enter key operation. Many WEB software designers may not notice that the submit is unified.
After a button is used, the page usually does not support the enter key. Therefore, the enter key must be supported and a submit must be set. The default enter key is used to operate the first submit on the page.
<Input type = "submit" name = "b1" value = "submit" onClick = "bt_submit_onclick ()">
After onClick is executed, go to action. OnClick is not required for automatic submission, so onclick is not required here.
<Input type = "button" name = "b1" value = "Submit" onClick = "bt_submit_onclick ()">
After onClick is executed, the jump file is controlled in the js file and onClick is required for submission. If there is 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>