Results 1 to 4 of 4
  1. #1
    amitnayak1 is offline Member
    Join Date
    Nov 2007
    Posts
    4
    Rep Power
    0

    Default About doGet & doPost methods

    In servlet class doGet & doPost methods automatically called.Who calls these two methods ?

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    8

    Default

    It will be called by the servlet container base on the get or post action from the client. For instance if you have an html form with the action equals to get then it will be handled in the doGet method and if the action equals to post then the action will be handled in the doPost method.

  3. #3
    amitnayak1 is offline Member
    Join Date
    Nov 2007
    Posts
    4
    Rep Power
    0

    Default

    Thank u very much for ur reply.
    I have again one question that servlet container calls a service() method to call doGet() or doPost() then if we will overload service() in our servlet class then can it be overloaded ? If yes what will be the use of doGet & doPost methods ?

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    8

    Default

    You need to know that actually Servlet is not just used for a web application, you can implement the Servlet for instance as a desktop based application. In the case of the service method implemented by the HttpServlet is because the contract defined in the servlet interface that should obeyed by the implementor.

    It would be better not to override the service method in the HttpServlet because the service method is implemented to handle the specific http request which then will be delegated to the specific method to handle a specific user request type, eg. the GET or POST.

    If you still need to override the method then don't forget to call the super.service() so the doGet or doPost will still executed after you if done with the service method logic that you've implemented.
    Last edited by wsaryada; 12-04-2007 at 07:06 AM.

Similar Threads

  1. Setting cookie from doPost
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-25-2008, 07:08 PM
  2. Example of doGet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-25-2008, 07:07 PM
  3. methods
    By Zensai in forum New To Java
    Replies: 10
    Last Post: 12-03-2007, 05:31 AM
  4. Methods
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-01-2007, 08:49 PM
  5. doPost question
    By Heather in forum Java Servlet
    Replies: 1
    Last Post: 07-09-2007, 03:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •