• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doGet() and doPost()

 
Val Lee
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both doGet() and doPost request,as well as,doGet() call doPost() in servlet.why to use?
thanks.
 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry I can't understand what you are talking about. doGet() does NOT have to call doPost(), in case you are looking at an example where the doGet just simply calls doPost. that just mean that particular servlet doesn't care whether it is GET or POST.
Kyle
 
Val Lee
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry,
e.g.
 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah, you define both doGet and doPost because your servlet wanna handle both GET and POST HTTP requests.
but if your doGet calls doPost, or doPost calls doGet, that just means your servlet treats both GET and POST in the same way, and generates the same response.
your doGet never has to call doPost, and the same for doPost. That example is just an example.
Kyle
 
Val Lee
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!I see!
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you just override doPost(req,res) alone , you are making an assumption that you support only POST requests. If in case, you call this servlet through browser address link, then you will get "500 Http Method Not Supported" error.
Usually, during development stage, we may want to check if the servlet functions well, by invoking the servlet directly from browser address bar. Making the servlet call doPost() from doGet() is an easy way to overcome this 500 server error (Default implementation) and helps us to proceed with our testing.
Regards,
Maha Anna
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic