If I load a servlet directly using welcome-file-list
attribute,which method of servlet gets invoke? doGet()
or doPost()
?
Asked
Active
Viewed 610 times
-1

Prasad Kharkar
- 13,410
- 5
- 37
- 56

Aneesh
- 1,703
- 3
- 24
- 34
-
It should be `service()` which will delegate the call to your Servlet's `doGet()` if implemented . – AllTooSir Jul 26 '13 at 11:32
-
@TheNewIdiot, welcome file will also form a URL, right? so every URL will invoke `doGet` method, right? Please correct me if I'm wrong – Prasad Kharkar Jul 26 '13 at 11:36
-
3The URL request will be `GET` , in case if the Container resolves the `request` to a Servlet , then it will invoke the `service()` method of that Servlet , inside the `service()` method the request shall be forwarded to the `doGet()` method because it is a `GET` request.`service()` is a life cycle method , `doGet()` is more of a convenience method. – AllTooSir Jul 26 '13 at 11:39
2 Answers
3
- Every URL generates a
GET
request. doGet()
method is invoked by default as the url isGET
request.- For
GET
request,doGet(HttpServletRequest, HttpServletResponse)
method of servlet is called.

Prasad Kharkar
- 13,410
- 5
- 37
- 56
1
Default method that gets called in servlet is doGet()
.Clicking a link, a bookmark, entering URL in browser address bar etc will fire a HTTP GET
request. If a Servlet is listening on the URL, then it's doGet()
method will be called. The HTTP POST
requests are usually only fired by a <form>
whose method attribute is set to post
Refer this.