• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

when to use these methods....

 
pardha saradhi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Parag Shah
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Parag
[ February 05, 2002: Message edited by: pshah72 ]
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this link for more infomation.
http://java.sun.com/docs/books/tutorial/servlets/
-arun
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic