File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes when to use these methods.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "when to use these methods...." Watch "when to use these methods...." New topic

when to use these methods....

pardha saradhi
Ranch Hand

Joined: Nov 08, 2001
Posts: 52
Hi I am new to servlets. I have some confusion about the following methods.
1.when to use doGet() -> it is clear
2.when to use doPost() -> it is clear
3.when to use Service() -> ???
4.what is the difference between doGet() and doPost()mehods?
5. What are HttpRequest and Httpresponse objects and why should we pass in service method as parameters.
Thanking you in advance

*** Share and let share ***
Parag Shah

Joined: Jan 23, 2002
Posts: 26
The service method of the Servlet is the first method called by the Servlet Container when it recieves a request to invoke the servlet. The service method calls doGet() or doPost() depending on whether it was a GET request or a POST request. We do not need to do anything with the service() method. Override doGet() and doPost() for dealing with GET and POST requests. A common way is to simply call the doPost() method from the doGet() method with the request and response objects, and implement the logic to identify the goal of the request in the doPost() method. Depending on the goal of the request the doPost() method must call another class or a method in the Servlet class to handle the request.
HTTPRequest contains information about the request which invoked the Servlet and HTTPResponse is where we must put the Servlets response to the request. The Servlet container will then serve the response to the client through the web server.
[ February 05, 2002: Message edited by: pshah72 ]
Do It Yourself Computer Science
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
Check this link for more infomation.

Sharing is learning
I agree. Here's the link:
subject: when to use these methods....
It's not a secret anymore!