In the initial stage of learning Javaweb, you will encounter the Doget and Dopost methods in HttpServlet. The first two days saw the difference between get and post requests in the servlet, which is summarized as follows: Servlets & JSP.
1: The size of the request data is different.
Because the data for a GET request is appended to the URL, and the amount of data in the URL is generally not more than 2K, the method of getting requests has limited data size. The Post request method is to put the data in the body of the message, so there is no theoretical limit on the amount of data. (but not in the actual operation can be too large)
2: Security is not the same
Because the data for the GET request is appended to the URL, the external user can easily see it, which is not safe from this point of view. The Post method, which is placed in the message body because it is a request, does not appear directly in the URL, so the data is safe from this point of view.
3: Bookmark Establishment
The GET request can be bookmarked, and the POST request cannot. For example, suppose you have a page that allows users to specify search rules. The user may be back after one weeks to get the original data, but there is already new data on the server.
4: Use of the method
Get is used for getting something, simply getting it, without making any changes to the server. Post then the user sends the data for processing and can modify the data on the server.
5: Whether the request power, etc.
Get requests are idempotent, and it just gets something that doesn't modify the content on the server. It can execute many times without any bad side effects. and post is not idempotent, the submitted data in the post body may be used for irreversible transactions. So from this point of view to be careful to use the Dopost () function.
If method= "POST" is not indicated in the form, it defaults to the HttpGet request. That is, the default state is to invoke a GET request.
In the initial stage of learning Javaweb, you will encounter the Doget and Dopost methods in HttpServlet.
(1) Doget method: Primarily to handle get requests in HTTP
(2) Dopost method: Mainly processing post requests in HTTP
What is the difference between a GET request and a POST request?
(1) get only a stream, the parameter appended to the URL, the size of the number is strictly limited and can only be a string
For example, http://localhost:8888/javaweb/getServlet?name=123
(2) Post parameters are passed through another stream, not through the URL, so can be very large, but also can pass the binary data, such as file upload.
When to use the Doget and Dopost methods:
1. Through the servlet to which the form is submitted, see whether the form's method is GET or post
2. Servlet,doget via link <a href...> access
3. The servlet address that you typed directly in the IE Address bar, doget