doGet and doPost methods in Servlet

Preface: The doGet and doPost methods are related to the way of passing parameters.

1. Introduction:

  The doGet and doPost methods implement the methods in HttpServlet, doGet is used to process Get requests, and doPost is used to process Post requests. When the client sends a request, it calls the service method of the servlet and passes a request and response object. The service determines whether the request is a get request or a post request, and then calls the doGet method or the doPost method.

2. Processing source:

  get method:

  (1) Client input URL address

  (2) url jump

  (3) Submit form form get method

  post method:

  (1) The form form is submitted by post

Third, the difference between the two:

  1. get is to obtain data from the server, and post is to transmit data to the server.

  2. The amount of data transmitted by the get method is small, the security is not high, and the execution efficiency is high. It is suitable for data with low confidentiality such as search. The amount of data transmitted by the post method is large, the security is high, and the execution efficiency is low. Account password, modify, delete and add information transmission.

  3. Get method: The form data is stored behind the URL address, and there is no message body in HTTP when all get methods are submitted.

   Post method: The form data is stored in the message body of the HTTP protocol and sent to the server in the form of an entity.
  4. Encoding conversion In the request request, each content obtained by the get method must be encoded and converted, and the tomcat encoding setting needs to be configured, while the post method only needs to set request.setCharacterEncoding("UTF-8").

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325025055&siteId=291194637