• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey i am sorry i had goofed up with the html when trying some things...

Thanks.
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Salil Vverma thanks for the explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic