can anyone pls. explain me why do we use service() method and what is the advantage of using doPost(), doGet() methods? P.S actually a similar topic was posted earlier but there seems to be some confusion in the explanation Thanks
hi, when you make a request to the servlet then the service method will be invoked automatically and in that method depending on the header information (get,put,post,etc) that doXXX() method will be invoked. In the books they say that donot try to override the service() method for httpservlet because it handles setup and dispatching to all doXXX methods.for generic servlets you can override service() method regards
It makes sense to override service() yourself only if one of the following conditions is met: 1. You are forwarding the request to another class (which may be another servlet or a JSP, for example) which itself needs to decide which method was used. 2. You are really, really sure that you will never need to respond at all to any of the other HTTP requests. Remember that HTTP is not just GET and POST; the service() method as supplied also handles things like HEAD and OPTIONS, and your server may also implement even more request types such as WebDAV. 3. If your code doesn't recognize the request type it calls super.service() to let the server code handle it.