I read in some book that overridding the service() is not a good idea. But I seen some codings in which service() method has been overridden. I want to know when it is needed to override the service() method. If we are overridding the service() method, what about doGet() and doPost().?
Assuming you are talking about the service method in an HttpServlet, then the answer is probably in the code where you've seen this happen. Basically all the service method does is delegates to the appropriate doXXX() method depending on the request. Since HTTP changes only very occasionally, it's very unlikely that you will need to alter its behaviour.