File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Why only doGet()  or doPost() & not service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why only doGet()  or doPost() & not service" Watch "Why only doGet()  or doPost() & not service" New topic

Why only doGet() or doPost() & not service

Syed Khateeb

Joined: Sep 30, 2006
Posts: 7
Why is it advised to override doGet()&/doPost() instead directly overriding service()?
Is it only because the possibility of having implementations for for other doXyz() methods is not possible?
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

You can override other doXXX methods as well. Most of the time you can accomplish what you want the servlet to do using the doGet and doPost methods.

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Chetan Raju
Ranch Hand

Joined: Aug 02, 2006
Posts: 109
By Overriding service() method, you need to implement logic to read the type of HTTP request (GET/POST). But, currently the service method already does this and dispatches the request to doPost()/doGet() method appropriately.
I agree. Here's the link:
subject: Why only doGet() or doPost() & not service
jQuery in Action, 3rd edition