This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes service() method 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 "service() method" Watch "service() method" New topic

service() method

Devaki Nihar

Joined: Apr 30, 2005
Posts: 20
I have read somewhere that service() method shd not overriden.
I have written a simple servlet which extends HttpServlet and overriden service() method there.
It works .
Then which is the correct practice? why ?
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Override either doPost or doGet (there are others too but they aren't commonly used).
The servlet container will call the service method.
The service method checks to see if the request is of type POST or type GET.
It will then call the appropriate method accordingly.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
It is sorta covered in the JavaRanch Style Guide.
subject: service() method
Similar Threads
Why is the Service() method in the servlet not overriden?
Which one gets first executed ?????????
How to display the resulting JSP of a servlet in another frame?
service() method overriden