Get and post differences for method in form form

Source: Internet
Author: User

First, the question of the proposed

Notice the action:getpostservlet/ in the form

This action comes with a parameter param4,

If the Get method is submitted, the background cannot receive this parameter;

If you submit using the Post method, you can receive this parameter in the background.

A simple explanation of the cause of the problem:

URLs submitted with the Get method are displayed as follows:

Http://localhost/mywebapp/getPostServlet/ =submit that is, the method is get when the action itself behind the parameter list will be ignored, the background can not receive this parameter, can only get the parameters in the form;

The URLs submitted using the Post method are displayed as follows:


That is, the Post method submits the form, the parameter is divided into two parts: the parameter in the action is placed in the address bar, and the parameter in the form is placed in the request header, so all the data backstage can be obtained.

For the Get method, the server side uses Request.QueryString to get the value of the variable, and for post, the server side uses Request.Form to get the submitted data.

For the Get method, the server side uses Request.QueryString to get the value of the variable, and for post, the server side uses Request.Form to get the submitted data. The request takes data from several sets in order, in order from the front to the back, followed by Querystring,form, and finally ServerVariables. The Request object searches for the variables in these collections in this order, and if there is a match, abort, and the latter is no more.

First, get and post definitions

The method property of the form element is used to specify the HTTP methods for sending the form;

When you use GET, the form data set is appended to the URL specified by the Action property of the form element;

When you use post, the form dataset is wrapped in the body of the request and sent.

Generate URL:USER.DO?LOGINID=ABC using Get Submit method

Get is simply stitching a URL, then requesting data directly from the service area, and the data set to be submitted to the server is included in the URL.

Use the Post submission method to generate

Post will wrap the data set of the form, that is, the key value pair of the LOGINID=ABC in the body of the request, to the server, and then request the data to the server.

Second, get and post differences

1. Security

If you use get to submit a form that validates the user name and password, it is generally considered unsafe because the user name and password appear on the URL, which in turn appears in the browser's history.

Obviously, you should use post in case of security requirements.

2. Coding

Get can only send ASCII characters to the server, while post can send characters from the entire ISO 10646.

The Enctype property for Get and post corresponds to the difference. Enctype has two values, the default value is application/x-www-form-urlencoded (all characters are encoded before sending)

The other is multipart/form-data (for file uploads) can only be used for post.

3, the length of the submission data.

ie restricts the requested URL length to 2,083 characters, which limits the data length of the get commit, and if the URL exceeds this limit, IE will not reflect when the form is submitted.

4. Cache

Because a get result directly corresponds to a URL, the resulting page of get can be cached by the browser, and post is generally not.

5. References and SEO

You can use a URI to refer to a Get result page, and the result of post is not, so must not be searched by the search engine.

The most essential difference:

1, get is used to obtain data from the server, and post is used to pass data to the server

If the Post method is used, the browser will send the data in the following two steps.

First, the browser connects the form processing server specified in the Action property, and once the connection is established, the browser sends the data to the server in a segmented transfer method.

On the server side, once the post-style application starts executing, the parameters should be read from a flag location, and once the parameters are read, the parameters must be decoded before the application can use the form values, and the user-specific server will explicitly specify how the application should accept the parameters.

Use the Get method:

The browser establishes a connection directly to the form processing server, then sends all the form data directly in a single transfer step, and then sends all the form data directly in a single transfer step.

2. Get adds the data in the form in the form of Variable=value, followed by the URL to which the action points, and both use "?". Connection, and each variable is connected using "&"; Post is where the data in the form is placed in the data body of the form, and is passed to the URL that the action points to, in the same way that the variable and value correspond.

Third, correct use of Get and post

Use get when and only if the form is idempotent.

Idempotent: The side effects of multiple identical requests are the same as the side effects of a single request.

You should use get if the commit request simply fetches the data from the server side rather than doing other operations, and there is no obvious side effect of multiple commits.

For example: Search engine query (HTTP://WWW.GOOGLE.COM/SEARCH?Q=ABC) and paging (

If submitting this request will have other actions and effects, you should use post.

For example: Modify the data in the database on the server, send an e-mail, delete a file, etc.

Another factor to consider is security.

Use the Post method if any of the following conditions are true:

A. The results of the request have persistent side effects, such as adding new rows of data within the database.

B. If you use the Get method, the data collected on the form may cause the URL to be too long.

C. The data to be transmitted is not ASCII encoded.

Use the Get method if any of the following conditions are true:

A. The request is to find resources, and the HTML form data is used only for searching.

B. The result of the request has no persistent side effects.

C. The total length of the data collected and the name of the input field in the HTML form does not exceed 1024 characters.

Iv. Browser Differences

The Ie6:url length is limited to 2,083 characters, and a warning appears after post to refresh the page without automatically re-post the data.

IE7 and IE6 are the same.

Firefox: Refreshing the page does not automatically re-post the data and a warning appears.

The difference between post and get is easy to ignore:

When method is get, the argument behind the URL in the Action property is ignored.

For example:

Action=insert.jsp?name=tobby Method=get, when we submit the actual URL is not name=tobby, he will be based on the contents of the form is reassembled into a URL, if there is a text box in the form,< Input type= "text" name= "Address" value= "Wuhan", then the URL will become Insert.jsp?addresswuhan.

Get and post differences for method in form form

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: 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.