Two Laptop Bag
The moose likes Servlets and the fly likes doPost and service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "doPost and service" Watch "doPost and service" New topic

doPost and service


Joined: Feb 10, 2002
Posts: 3
Can anybody tell me the difference between service method and doPost in a HttpServlet.

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

The service() method receives standard HTTP requests and dispatches them to the doXXX methods defined in the servlet class.
Suppose u specify method="post" in your HTML from then the service method of your servlet will be called and from that method doPost method gets called.

Doug Wang
Ranch Hand

Joined: Oct 05, 2001
Posts: 445
So dont override the default service() method. Just leave it alone. Thus you gain flexibility.
[ April 23, 2002: Message edited by: Doug Wang ]

Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep
Gagan Indus
Ranch Hand

Joined: Feb 28, 2001
Posts: 346
yeah , Servlet API framework is general in nature : init() service() destroy().
HttpServlet gets specific to HTTP protocol so doGet() , doPost() etc r there

Gagan (/^_^\) SCJP2 SCWCD IBM486 <br />Die-hard JavaMonk -- little Java a day, keeps you going.<br /><a href="" target="_blank" rel="nofollow">My Blog</a>
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at JavaRanch's naming policy. . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
I agree. Here's the link:
subject: doPost and service
It's not a secret anymore!