1: The method for submitting a form is different.
Use the get method to submit a form. The request parameters are in the request header. You can use the request. getQueryString () method to obtain the request parameters,
The return value of the request. getContentLength () method is-1. The form is submitted using the post method, and the request parameters are stored in the request body.
Request. getQueryString method cannot obtain the request parameter. request. getContentLength () can obtain the length of the request body.
The get method is used to submit a form. Because the request form is stored in the request header, it is displayed in the browser address bar.
It will not be displayed in the address bar, which is relatively safe. Because different browsers have different restrictions on the length of the address bar, The get method is used.
When the request is submitted, the length of the request parameter is also limited. If the request parameter submitted by the post method is placed in the request body, the length of the request body is not limited, and the length of the request parameter is not limited.
The get method submits a form in character mode, while the post method submits form characters and bytes.
Understand the http request process of post and get through an instance
Through the above analysis, I have already understood GET and POST, and I can also feel that the difference between them is that one is to use it, and the other is to update and modify it.
Next we will use HTTPLOOK to see how they make HTPP requests and how they are transmitted.
First, create two jsp pages for testing:
The first page is post_get_jsp (the code is as follows ):
The code is as follows: |
Copy code |
<% @ Page language = "java" contentType = "text/html; charset = GB18030" PageEncoding = "GB18030" %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> <Html> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = GB18030"> <Title> Insert title here </title> </Head>
<Body> <Form name = "aaForm" action = "http: // localhost: 8080/post_get/test. jsp" method = "get"> <Input type = "text" id = "text1" name = "text1" value = "dadfdf"> <Input type = "submit" id = "submit1" name = "submit2" value = "submit"> </Form> </Body> </Html> |
The second page is test. jsp (the code is as follows ):
The code is as follows: |
Copy code |
<% @ Page language = "java" contentType = "text/html; charset = GB18030" PageEncoding = "GB18030" %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> <% String a = request. getParameter ("text1 "); Out. println (); %> <Html> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = GB18030"> <Title> Insert title here </title> </Head> <Body>
<H1> ddfdgdg </Body> </Html> |
Simply put, the http request:
<Request line>
<Headers>
<Blank line>
<Request-body>
In an HTTP request, the first line must be a request line to describe the request type, resources to be accessed, and the HTTP version used. Next is a header section, which describes additional information to be used by the server. After the header is a blank line, you can add any other data.
Start testing post submission
The http request is as follows:
Start Testing get submission
The http request is as follows:
Difference between POST and GET
①. GET is generally used to obtain/query resource information, while POST is generally used to update resource information.
②. From the preceding http request, we can see that GET is used to append the request data to the URL? Separate and connect parameters. And the string has been encrypted. The post submission is put in the http package. From this point of view, the address bar of the GET request will change. RUL attaches the requested data, while the POST address bar will not change, and the UTL will not change. A deeper understanding of the security of GET is not high, so it is easy to expose information.
③. In addition, although the http protocol does not limit the size of transmitted data or the url length, the browser actually limits the url, in this way, the size of the data transmitted by GET is limited with the URL length. In contrast, there is no limit on POST because it does not pass values through URLs.