service()
method is actually the main method that is expected to perform the actual task. The servlet container calls the service()
method to handle requests coming from the client/browsers and to provide the response back to the client.service()
method checks the HTTP request type and calls the respective methods as required.public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException{
}
The container calls the service()
method and service method invokes doGet(), doPost(), doPut(), doDelete()
, methods as needed. So you have nothing to do with service()
method but you override either doGet()
or doPost()
depending on the request you receive from the client-end.