jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes DoPost Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "DoPost" Watch "DoPost" New topic


Arathi Raj
Ranch Hand

Joined: Nov 22, 2002
Posts: 90

What is the advantage of calling doGet method from doPost?

Arathi Raj
Ranch Hand

Joined: Nov 22, 2002
Posts: 90
posted August 03, 2005 09:17 PM

Operations requested through POST can have side effects for
which the user can be held accountable, for example, updating
stored data or buying items online.

Can anyone explain me this in detail. How Post will have side effects. when sendind date through this method is safe?

Also I want to know

GET method retrieve data by SQL queries POST to update data.
What does these mean. Explain this also.

Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 951

Though the HTTP specifications says that POST may have side effects and GET not, when implementing these methods in servlet, there is no difference. The doGet methods may have side effects. If you require same functionality you can call goGet in doPost or vice versa.

The Servlet specification specify the intends and not the actual implementation of these methods.


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
HTTP 1.1 spec declares that GET, HEAD, and PUT are to be idempotent, meaning you can do the same things over and over again without side effects on the server. This doesn't mean that the same request always returns the same response, just that identical requests don't have negative consequences.

POST is not considered idempotent, so identical POST requests can have side effects. This is the example from the HFS&J Book: (I am hopping Bryan, Kathy and Bert won't mind me borrowing their example )
  • Diane hits the CHECKOUT button at a book web site
  • Browser sends a POST request with her info
  • Container gets the request and sends it to the appropriate servlet, which electronically debits Diane's bank account and updates the book store's database
  • The Servlet didn't send an obvious response, and Diane still sees the same shopping cart page, and thinks, "Maybe I didn't click it right. I better hit the CHECKOUT button again..."
  • Browser sends another POST request with her info
  • Container happily recieves the request, and sends it to the same servlet, which debits her account, and sends her another book!
  • As mentioned earlier though, just because the spec declares that GET is idempotent and POST is not is not a guarentee on functionality. A GET request can just as easily have negative side effects, but it is considered bad design.

    “Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
    I agree. Here's the link: http://aspose.com/file-tools
    subject: DoPost
    It's not a secret anymore!