my dog learned polymorphism*
The moose likes Servlets and the fly likes idempotent vs non-idempotent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "idempotent vs non-idempotent" Watch "idempotent vs non-idempotent" New topic
Author

idempotent vs non-idempotent

Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

GET method is said to be idempotent and post method is said to be non-idempotent. So will it create any problem when we use non-idempotent methods like post when I send identical requests?

If I want to send identical requests should I use only doGet()?

Pls tell me where my logic is going wrong


Thanks and regards
Rahul Roy.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

While the GET method was intended to be idempotent, you can actually do anything you want with code on the server. Same with POST operations.

If you want to follow the intentions of the HTTP protocol, be sure to code your apps such that GETs don't change server state, and to use POSTs when server state may change.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lucky Chawla
Greenhorn

Joined: Aug 08, 2006
Posts: 22
can anybody tell me the diff between idempotent and non-idempotent, w.r.t doGet and doPost methods
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Lucky Chawla,
Two things:

OneWelcome to JavaRanch!

We're pleased to have you here with us in the Servlets forum, but there
are a few rules that need to be followed, and one is that proper names are
required. Please take a look at the
JavaRanch Naming Policy and
adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You can change it here


Second:
In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.
In particular please see:
UseRealWords


Abbreviations such as "u" or "ur" in
place of "you" and "you are" or "you're" confound language translation software making
it hard for our non-English speaking members to read your posts.
"plz" is not a word in the English language.

Please edit your last post and remove the "w.r.t.." section.
"diff" is not a word in the English languge.

Again, welcome to JavaRanch and good luck with your question.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Lucky Chawla
Greenhorn

Joined: Aug 08, 2006
Posts: 22
Ya you are right , I myself think my lanugage to ask a question is not correct. I will recorrect my question:
can anybody tell me the difference between idempotent and non-idempotent, with respect to doGet and doPost methods ?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

HttpServlets are built to work over HTTP so maybe it's better to understand the intent of the designers of the HTTP spec.
This page does a good job explaining it:
http://en.wikipedia.org/wiki/HTTP#Idempotent_methods

As Bear mentioned, it is up to you to follow these recommendations (or not to).
Nothing in the servlet spec will enforce this.
Browsers will warn people if they try to refresh or back into a non-cached page that was created from the result of a POST operation.
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Originally posted by Ben Souther:
HttpServlets are built to work over HTTP so maybe it's better to understand the intent of the designers of the HTTP spec.
This page does a good job explaining it:
http://en.wikipedia.org/wiki/HTTP#Idempotent_methods

As Bear mentioned, it is up to you to follow these recommendations (or not to).
Nothing in the servlet spec will enforce this.
Browsers will warn people if they try to refresh or back into a non-cached page that was created from the result of a POST operation.


Hello Mr.Ben Souther,


I have a doubt.

1. Senario.

As per your suggested link Idempotent means multiple identical requests should have the same effect as a single request

does it mean...

I want to create a small application. In which, there is an option for buying books which includes note-books also.

First my customer wanted to buy a note-book through my web-site after getting the confirmation from the server, he wanted to buy same book again.

In this situation what should I do ? am I supposed to use only doPost() instead of doGet()???

If I use doGet() will my customer be able to buy only one book???

Don't idempotent methods recognise my 2 request?

Regards,
Rauhl Roy.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: idempotent vs non-idempotent
 
Similar Threads
Why two methods GET and POST? Only one could serve the purpose
a question about HTTP method
Using get() and post() together
ajax not working with jsp
what is differance between the get/post method?