This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes overriding both doget() and dopost() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "overriding both doget() and dopost()" Watch "overriding both doget() and dopost()" New topic
Author

overriding both doget() and dopost()

geet kaur
Ranch Hand

Joined: Sep 03, 2008
Posts: 78

If i override both doget() and dopost() in a servlet,then how is it decided that which method will be called???
Louis Bros
Ranch Hand

Joined: Jun 03, 2011
Posts: 54

It depends on the HTTP request.

If you use an HTML form to access your servlet and the method is set to post, then the doPost() method will be called.

<form method="post" action="YourServlet.do">

If you set the form method to get or if you access the servlet directly via a url then the doGet() method will be called.

<form method="get" action="YourServlet.do">

http://mysite..com/YourServlet.do

Also I believe if you don't set the form method then the default is a get request.


OCA7
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

Actually, neither will be called as doget() and dopost() are not defined by the Servlet Spec. It's doGet() and doPost().


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1075
    
    1

Hi Geet

If are asking your question from Front end (JSP / HTML) perspective then Loius has provided an explanation

But if are asking from server side perspective then answer is -->
once we send a GET/POST request to our server code then doService() method (generic method) decides whether to call doGet() OR doPost() depending upon request type
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overriding both doget() and dopost()
 
Similar Threads
POST or GET
I don't doGet() it!
service() in HttpServlet
doGet() and doPost()
Making doPost call doGet