Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which method will invoke? doGet() or doPost()

 
Nagaraj Shivaklara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can you please tell me which method will invoke in the below senario?

what happens if i submit a form without mentioning the method type(get or post) and in called servlet if i have only doPost() method; will doPost() method execute?
 
Prasad Krishnegowda
Ranch Hand
Posts: 667
4
Eclipse IDE Java Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't specify a method type, by default it is a GET request, and if you have only doPost(), it doesn't get called, an HTTP status 405 is returned..

P:S: Why can't you try this yourself, instead of waiting for someone to give an answer for you?
 
Janarthanan Rajendran
Greenhorn
Posts: 7
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By default its GET , its always better to create a service method and call that inside doGet and doPost if your are planning to use both

Regards,
Jana
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64844
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Janarthanan Rajendran wrote:its always better to create a service method and call that inside doGet and doPost if your are planning to use both

No it is not. GET and POST should do different things. It's very short-sighted and a violation of the HTTP contract to just have them to the same thing.
 
Nagaraj Shivaklara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK,

Then can you please tell me which method will invoke if i have only doPost method in servlet and did not mention any method type in the form submission?


Bear Bibeault wrote:
Janarthanan Rajendran wrote:its always better to create a service method and call that inside doGet and doPost if your are planning to use both

No it is not. GET and POST should do different things. It's very short-sighted and a violation of the HTTP contract to just have them to the same thing.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64844
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your extending class? None. The base class will return a 405 error.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic