wood burning stoves 2.0*
The moose likes Servlets and the fly likes Making doPost call doGet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Making doPost call doGet" Watch "Making doPost call doGet" New topic

Making doPost call doGet

jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
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?
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
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.

So much trouble in the world -- Bob Marley
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
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.

/ JeanLouis<br /><i>"software development has been, is, and will remain fundamentally hard" (Grady Booch)</i><br /> <br />Take a look at <a href="http://www.epfwiki.net/wikis/openup/" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
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.
Robert Gagliardo

Joined: Nov 15, 2001
Posts: 24
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Making doPost call doGet
Similar Threads
doPost() processes - doGet() displays
Reverse2Servlet doXxx( question )
Dont want the control to return to the servlet and execute after the forward
Can I call a servlet directly from HTML