9

the difference in term of the flow, i know that doGet() is the pre-processing and dopost is post-processing, but what is that?

shamil khairi
  • 93
  • 1
  • 1
  • 6
  • The docs should probably be answering this question for you, e.g., where it says "Called by the server (via the service method) to allow a servlet to handle a GET request." – Dave Newton Nov 20 '14 at 13:51

2 Answers2

15

the difference in term of the flow, i know that doGet() is the pre-processing and dopost is post-processing, but what is that?

Actually, the methods are nothing to do with "pre-processing" and "post-processing".

To understand what the methods are for, you need some basic understand of the HTTP protocol.

HTTP is a request-reply protocol: the client (e.g. a web browser) sends a request, and the server (e.g. a web server) responds with a reply. Each request consists of a "request-line", a series of "header" lines and optionally a "body". A typical request-line looks like this:

  GET http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1

The three parts of this line are:

In fact, the HTTP specification defines 8 standard HTTP request methods (GET, PUT, POST, DELETE, HEAD, OPTIONS, TRACE & CONNECT) each of which has a different meaning. (Other methods are defined by other specifications.)

The doGet and doPost methods in the Servlet API are methods for processing HTTP GET and POST requests respectively. In fact there are other "doXxxx" methods matching the other standard HTTP methods ... apart from CONNECT. (The semantics of CONNECT are not applicable to a servlet ...)

For more information, refer to the HTTP 1.1 Specification, and the HttpServlet javadoc.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • I would add that a GET (like HEAD) *methods to any resources SHOULD NOT have side effects that would lead to erroneous behavior if these responses are taken from a cache* (extract from HTTP 1.1 specification cited above) => GET should only be use to read something but not to change something – Serge Ballesta Nov 20 '14 at 14:08
  • @SergeBallesta - Noted. I won't do that because it is not my intention to give a complete tutorial on HTTP methods. All I'm trying to explain is the (real) purpose of the servlet `doXxx` methods. – Stephen C Nov 20 '14 at 21:32
11

This link Detail

doGet() and doPost() are HTTP requests handled by servlet classes.

In doGet(), the parameters are appended to the URL and sent along with header information. This does not happen in case of doPost(). In doPost(), the parameters are sent separately. Since most of the web servers support only a limited amount of information to be attached to the headers, the size of this header should not exceed 1024 bytes. doPost() does not have this constraint. Usually programmers find it difficult to choose between doGet() and doPost().

doGet() shall be used when small amount of data and insensitive data like a query has to be sent as a request. doPost() shall be used when comparatively large amount of sensitive data has to be sent. Examples are sending data after filling up a form or sending login id and password.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Benjamin
  • 2,257
  • 1
  • 15
  • 24