aspose file tools*
The moose likes Servlets and the fly likes How does the service() identifies which among doPost or doGet to be called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How does the service() identifies which among doPost or doGet to be called" Watch "How does the service() identifies which among doPost or doGet to be called" New topic
Author

How does the service() identifies which among doPost or doGet to be called

James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

If i specify a GET in the action attribute of the html and define doPost() in the servlet then nothing goes wrong. Servlet is called and the service method calls the doPost().
But the vice-versa is not happening?? i.e POST in html and doGet() in servlet.
What is the logic behind this ?? what is that i am missing??


SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

James Tharakan wrote:If i specify a GET in the action attribute of the html and define doPost() in the servlet then nothing goes wrong. Servlet is called and the service method calls the doPost().

Can you post that code here?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Hey i am sorry i had goofed up with the html when trying some things...

Thanks.
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

Hey James,

As you know the service method expects two parameters request and response, It uses req.getMethod() function to get the http method name. Its possible values might be Get,Post,Option,Head,Put,Delete and trace. Then it calls the corresponding function.

doGet() and doPost() have the default implementation of throwing http error that http.method_get_not_supported/http.method_post_not_supported for get and post respectively.

It is good that you got the issue resolved with your jsp yet I think this explanation would clear your understanding about how service method works and identifies which http method to call.


Regards
Salil Verma
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Salil Vverma thanks for the explanation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does the service() identifies which among doPost or doGet to be called