This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Can anyone explain Idempotent requests? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Can anyone explain Idempotent requests?" Watch "Can anyone explain Idempotent requests?" New topic
Author

Can anyone explain Idempotent requests?

Rafi Fareen
Ranch Hand

Joined: Aug 28, 2009
Posts: 75
hi guys,

reading this book HFSJ, but i have not understood the explanation of Idempotent.

I have a form which uses GET request, i submit the form and in the servlet i use the form data to update a record in the database.
does that mean the record in database is not updated? if not such kind of update, than what exactly it means.

thanks

rafi
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

GET is inherently supposed to be idempotent i.e. generally get requests can be made multiple times without making any effects. If you submit a form using GET request and update the database, then multiple requests might make an effect. So in that case your GET request won't be idempotent. We should try to avoid such situations where a GET (or other idempotent HTTP methods) make an effect when multiple requests are made using them...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
What I understand is basically this. In realitity there is no such thing as idempotent ! Because both get and post can be used to change values in the server side or cause side effects.

However, I feel the spec might state that we are supposed to use the GET such that it should not cause any sideeffect. Hence, we should supposedly use GET as idempotent and post as non-idempotent

I think the JAVA guys at SUN should alltogether stop this concept or create some other mechanism as GET can be used to cause sideffects!


Working on my SCWCD so I can be a J2EE consultant earning millions of dollars and showing everyone I can
Ankur Jain Kothari
Ranch Hand

Joined: Feb 08, 2010
Posts: 154
dude Get....Put.....Trace are idempotent....put and trace are safe too....GET is supposed to be idempotent....SUN recommends that GET should be used in such a way that nothing gets changed in the server.....because that is the underlygin concept of GET method.....you can change the data doesnt mean you should do it. its just a bad way of implementing it.....


Do What You Wanna Be....Taking Things The Way They Come
scjp 1.6 91 percent, scmad 90 percent(rounded off to nearest integer)
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Swagato Bhatta wrote:I think the JAVA guys at SUN should alltogether stop this concept or create some other mechanism as GET can be used to cause sideffects!

This has nothing to do with Java. This is how GET method is defined in the HTTP specification. It is a general guideline to make GET requests idempotent, but no one can stop you from designing your application in such a way that GET requests are non-idempotent...
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
Swagato Bhatta wrote:What I understand is basically this. In realitity there is no such thing as idempotent ! Because both get and post can be used to change values in the server side or cause side effects.

However, I feel the spec might state that we are supposed to use the GET such that it should not cause any sideeffect. Hence, we should supposedly use GET as idempotent and post as non-idempotent


Your understanding is correct!


SCJP 1.5(97%) My Blog
Ankur Jain Kothari
Ranch Hand

Joined: Feb 08, 2010
Posts: 154
twist in the tale
Rafi Fareen
Ranch Hand

Joined: Aug 28, 2009
Posts: 75
Ankit Garg wrote:GET is inherently supposed to be idempotent i.e. generally get requests can be made multiple times without making any effects. If you submit a form using GET request and update the database, then multiple requests might make an effect. So in that case your GET request won't be idempotent. We should try to avoid such situations where a GET (or other idempotent HTTP methods) make an effect when multiple requests are made using them...


you said :
generally get requests can be made multiple times without making any effects.

and
f you submit a form using GET request and update the database, then multiple requests might make an effect. So in that case your GET request won't be idempotent.

we should try to avoid situations


if you explain this texts of yours using a real example, in the sense that:

1. there is two form purchaseGET.html & purchasePOST.html, both of them accessing same servlet
2. the servlet is performing some update in the database
3. if this servlet is invoked multiple times from either of the two html files, which one will have side effects and which one won't ?
4. which of the two methods are recommended by HTTP Specification?


reading one reply i feel that oh this idempotent stuff are just theory or lets say an advise and doesn't exists in real life, but reading other one i get confused saying it will have side effects or we should avoid using them.

If anyone can post one perfect example with a proper explanation {showing that ok, if we invoke this servlet with GET we have these advantages/disadvantages, effects/side effects, recommended/not recommenned, good programming behavior or not}, that example can always be used as a sample to everyone who is confused with the topic.

Searching through the forum, i found few threads on this topic, where everyone says different things.

Thanks for your replies everyone,

Regards,

Rafi


Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Rafi Fareen wrote:1. there is two form purchaseGET.html & purchasePOST.html, both of them accessing same servlet
2. the servlet is performing some update in the database
3. if this servlet is invoked multiple times from either of the two html files, which one will have side effects and which one won't ?

Both will have side effects
Rafi Fareen wrote:4. which of the two methods are recommended by HTTP Specification?

For this case POST would be the recommended method to make a request to that servlet as it is making a side effect...
Rafi Fareen
Ranch Hand

Joined: Aug 28, 2009
Posts: 75
Ankit Garg wrote:
Rafi Fareen wrote:1. there is two form purchaseGET.html & purchasePOST.html, both of them accessing same servlet
2. the servlet is performing some update in the database
3. if this servlet is invoked multiple times from either of the two html files, which one will have side effects and which one won't ?

Both will have side effects
Rafi Fareen wrote:4. which of the two methods are recommended by HTTP Specification?

For this case POST would be the recommended method to make a request to that servlet as it is making a side effect...


OK, Thanks alot.
Bunty Naagar
Greenhorn

Joined: Feb 27, 2007
Posts: 14
Sorry to be off topic but when I first read this term in the HFSJ book- I thought they made it up( I am new to web stuff)
I found it even more hillarious on discovering that it actually existed!!
Just pronouncing it makes me giggle

SCJP 5, SCWCD 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can anyone explain Idempotent requests?