• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overriding both doget() and dopost()

 
geet kaur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 54
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, neither will be called as doget() and dopost() are not defined by the Servlet Spec. It's doGet() and doPost().
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic