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 Murach's Java Servlets and JSP this week in the Servlets 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: 6661

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.
Consider Paul's rocket mass heater.
subject: Why only doGet() or doPost() & not service
Similar Threads
Differences Between doGet(),doPost(),service()
Multi-threading in servlets
When a request is sent to the servlet
why we should not override service() method in a servlet
Why Not Overload Service Method.