| Author |
which method will invoke? doGet() or doPost()
|
Nagaraj Shivaklara
Ranch Hand
Joined: Dec 16, 2008
Posts: 72
|
|
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?
|
Thanks n Regards,
Nagaraj S K
|
 |
Prasad Krishnegowda
Ranch Hand
Joined: Apr 25, 2010
Posts: 503
|
|
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?
|
Regards, Prasad
SCJP 5 (93%)
|
 |
Janarthanan Rajendran
Greenhorn
Joined: Nov 07, 2011
Posts: 7
|
|
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
Joined: Jan 10, 2002
Posts: 56192
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Nagaraj Shivaklara
Ranch Hand
Joined: Dec 16, 2008
Posts: 72
|
|
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
Joined: Jan 10, 2002
Posts: 56192
|
|
|
In your extending class? None. The base class will return a 405 error.
|
 |
 |
|
|
subject: which method will invoke? doGet() or doPost()
|
|
|