Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Making doPost call doGet

 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Core Servlets and JSPs, when a POST method is used, many of their examples have doPost() call doGet(). I'm just curious what is seen in the real world? I'm used to just using doPost(), even if there is no overriding doGet method. Is one way preferred over the other for some reason?
Thanks!
Jason
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your page can, and is accessed through doGet (i.e clicking on a link, typing the address in the URL), and you don't have a doGet method, you will get an error. If theere is a chance that your page can be accessed by both methods, it's good to handle both.
 
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most of the time, the navigation through a web application is done using links. So the doGet() method has to be implemented.
And when you have forms, the POST method is often the one specified.
So the doPost() has to be implemented.
That's why the way it is done within Core servlets is a good one. Both methods are handled, but the script is only written once.
Another way is the IBM VAJ one.
it creates a performTask(request, response) methog, and doGet() doPost() call this method.
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've implemented a similar solution going through the Cattle Drive Servlets and JDBC, and it works great (especially with subclasses). Mainly I was curious if you've written an HTML form the uses POST, would you really want to have doPost call doGet. But I guess after reading y'alls replies, it is just safer to get in the habit of implementing both just in case.
Thanks!
Jason
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to handle both doPost(...) and doGet(...) one simple way is to just overwrite the service(...) method, which calls doPost(...), doGet(...) and the other do*(...) methods.
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic