• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doGet() and doPost()

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both doGet() and doPost request,as well as,doGet() call doPost() in servlet.why to use?
thanks.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry,
e.g.
 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!I see!
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic