1, get is used to obtain data from the server, and post is used to pass data to the server.
2, get adds the data in the form in variable=value form to the URL that the action points to, and both uses the "?" connections, and each variable uses a "&" connection; The post is to place the data in the form in the form's data body, passing it to the URL that the action refers to, according to the variable and the value.
3, get is not safe, because in the transfer process, the data is placed in the requested URL, and many of the existing servers, proxy servers, or user agents will be the request URL to log files, and then put in a place, so that there may be some privacy information by a third party to see. In addition, users can also see the submitted data directly in the browser, some system internal messages will be displayed in front of the user. All operations for post are not visible to the user.
4, get transfers the amount of data is small, this is mainly because of the URL length limit, and post can transfer a lot of data, so the upload file can only use post (of course, there is a reason, will be mentioned later).
5, the value of the data set of the Get restriction form form must be an ASCII character, and the post supports the entire ISO10646 character set. The default is to use ISO-8859-1 encoding
6, get is the default method for form.
The following comparisons are very very very useful:
has been doing Java Web development for some time, there is a problem is always bothering me, is garbled problem, is basically the Internet to find solutions (online data really a lot), are a lot of how to solve this kind of garbled problem, but not a few put the ins and outs of the problem to say clearly, Sometimes read some articles, think they understand, but in the development of garbled problem and like ghosts out scary, really head big! This article is my long time and garbled to do some understanding of the accumulation of the struggle, but also hope to have more friends to give guidance and supplement.
form has 2 methods to submit the data to the server, get and post, respectively.
(i) Get submit
1. First of all, the client (browser) Form table single Get method is how to encode the data and submit it to the server side.
for Get methods, the data is concatenated to the requested URL as an argument, such as: Http://localhost:8080/servlet?msg=abc
(very common a garbled problem will appear, if the URL appears in Chinese or other special characters, such as: http://localhost:8080/servlet?msg= Hangzhou, server-side easy to get garbled), after the completion of the URL stitching, The browser URL to the URL encode, and then sent to the server, the URL encode process is a part of the URL as a character, according to some encoding (such as: UTF-8,GBK, etc.) encoded into a binary byte code, and then each byte with a string containing 3 characters "%xy "Indicates that XY is the two-bit hexadecimal representation of the byte. I said here may not be clear, the specific introduction can look at the introduction of the Java.net.URLEncoder class here. Understand the process of URL encode, we can see 2 very important questions, first: The URL encode characters are generally non-ASCII characters (generally speaking), and then the popular word is except the English letter text (such as: Chinese, Japanese, etc.) to carry out the URL encode, So for us, the URL of the English alphabet will not appear the server gets garbled problem, the occurrence of garbled characters are in the URL with the Chinese or special character caused; second: URL encode exactly according to that encoding for character encoding? This is the browser thing, and different browsers have different practices, the Chinese version of the browser will generally default to use GBK, by setting up the browser can also use UTF-8, may be different users have different browser settings, but also create a different encoding method, So many web site practices are first in the URL inside the Chinese or special characters with JavaScript to do the URL encode, and then splicing the URL to submit data, that is, for the browser to do the URL encode, the advantage is that the site can be unified get method to submit data encoding method. completes the URL encode, the URL is now an ASCII-scoped character, and then the ISO-8859-1 encoding is converted to a binary with the request header sent together. Here want to say a few more, for Get method, no request entity, contains the data URLs are in the request header, the reason why the URL encode,I personally feel the reason is: for the request to the end of the head is to encode the iso-8859-1 encoding into binary 101010 .... Pure data in the Internet transmission, if the direct containing Chinese and other special characters do ISO-8859-1 encoding will lose information, so first do the URL encode is necessary.
2. How server-side (Tomcat) gets data to be decoded.
The first step is to decode the data with iso-8859-1, for Get method, Tomcat gets the data is the ASCII range of request header characters, where the request URL with parameter data, if the parameters in Chinese and other special characters, then the current URL Encode after the%XY state, first stop, we first say the developer general access to data process. Usually everyone is request.getparameter ("name") to get parameter data, we are in the request object or the data are decoded, and decoding process is not specified in the procedure, here to say, there are a lot of novice said with Request.setcharacterencoding ("character set") can specify the decoding method, in fact it is not , see the servlet's official API to explain this method: Overrides the name of the Character encoding used in the "this" request. This method must is called prior to reading request parameters or reading input using Getreader (). It can be seen that there is nothing for him to do. So exactly what encoding the data to decode it, this is Tomcat thing, default default is Iso-8859-1, so we can find out why get request with Chinese parameters in the server is garbled, because in the client is generally used UTF-8 or GBK to the data URL encode, here with the iso-8859-1 way URL decoder obviously not, in the program we can directly
Java Code
1. New String (Request.getparameter ("name"). GetBytes ("Iso-8859-1"), "client-specified URL encode encoding")
restores the bytecode, and then decodes the data in the correct way, the articles on the Web are usually configured in Tomcat
XML Code
1. <connector port= "8080" protocol= http/1.1 "maxthreads=" connectiontimeout= "20000" redirectport= "8443" uriencoding= "GBK"/>
this is how to get Tomcat to URL Decoder,url decoder in the specified way after fetching the data
(i) post submission
1. Client (browser) Form table Single Post method is how the data is encoded and submitted to the server side.
the data to be sent in the Post method also has to be URL encode, so what is the encoding method?
in the HTML file where the form resides if there is a segment <meta http-equiv= "Content-type" content= "text/html" charset= Character Set (Gbk,utf-8, etc.) "/& gt;, then the post is encoded in the encoding specified here. generally everyone thinks this code is to let the browser know what character set to explain the Web page, so the site will put it in the most front-end HTML code, as far as possible not garbled, in fact it also has a role is specify form form of the Post method to submit data URL encode encoding method . From here you can see that for the number of Get methods, the browser to the data URL encode encoding is a browser settings to determine, (you can use JS to do uniform designation), and the Post method, developers can specify.
2. How server-side (Tomcat) gets data to be decoded.
If you use the Tomcat default setting and do not have a filter, such as encoding settings, then he is also decoded with iso-8859-1, but Request.setcharacterencoding ("character set") can be useful.
I found that what the Tomcat was doing was that the code was not specified in the request header, and that encoding would be encoded in that way if the request header had specified a coding method.
There are 2 articles recommended, address respectively is
Simple URL code: http://www.cnblogs.com/yencain/articles/1321386.html ;
Table garbled problem when submitting data by post method: http://wanghuan8086.javaeye.com/blog/173869
Using post is important in the HTML file where the form is located if there is a segment <meta http-equiv= "Content-type" content= text/html; charset= Character Set (Gbk,utf-8, etc.) "/>
strongly recommends using post submission