In B/S applications, the data interaction between the front and the backend is completed through the Form form in HTML. Form provides two ways of data transmission - get and post. Although they are both ways of submitting data, they are indeed very different when actually transmitted and may have serious impacts on the data. Although the web container has blocked some differences between the two in order to facilitate the acquisition of variable values, it will be helpful to understand the differences between the two in the future programming.
The get and post methods in Form correspond to the GET and POST methods in the HTTP protocol respectively during data transmission. The main differences between the two are as follows:
1. Get is used to obtain data from the server, while Post is used to pass data to the server.
2. Get adds the data in the form to the URL pointed to by the action in the form variable=value, and the two use "?" to connect, while the "&" connects between each variable; Post is to place the data in the form in the data body, and passes it to the URL pointed to by the action in the way the variable and value corresponds to the value.
3. Get is not safe because during the transmission process, data is placed in the requested URL. Nowadays, many existing servers, proxy servers or user agents will record the requested URL into the log file and then place it somewhere, so that some privacy information may be seen by third parties. In addition, users can also directly see the submitted data on the browser, and some internal system messages will be displayed in front of the user. All operations of Post are invisible to the user.
4. The amount of data transmitted by Get is small, which is mainly due to the limitation of URL length; and Post can transfer a large amount of data, so you can only use Post when uploading files (of course there is another reason, which will be mentioned later).
5. Get restricts the value of the data set of Form forms to be ASCII characters; while Post supports the entire ISO10646 character set.
6. Get is the default method of Form.
To sum up:
Get method: pass data parameters in the URL string itself, and can be read directly from the 'QUERY_STRING' variable on the server side. It is efficient, but lacks security and cannot process complex data (it can only be strings, for example, in servlet/jsp, it cannot handle Java functions such as vector);
Post method: In terms of transmission method, parameters will be packaged and transmitted in the datagram and read from the CONTENT_LENGTH environment variable, which is convenient for transmitting larger data. At the same time, because the data is not exposed in the browser's address bar, the security is relatively high, but such processing efficiency will be affected.