How does the servlet container
know whether to call doGet
or doPost
method.
When I make a get request doGet
is called, When I make a post request doPost
is called , but where is the logic to decide this .
You never really call doGet()
or doPost()
(the service() method will, and it is called by the Web container as you read in the lifecycle).
The service()
method detects the HTTP method used and delegates to doGet()
, doPost()
and other methods which process HTTP requests in a HTTPServlet
. It also encapsulates the ServletRequest
and ServletResponse
objects in HttpServletRequest
and HttpServletResponse
objects which contain additional context data from the HTTP headers.
Tahnks to @helderdarocha.