aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Why is PUT considered as  idempotent..? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Why is PUT considered as  idempotent..?" Watch "Why is PUT considered as  idempotent..?" New topic
Author

Why is PUT considered as idempotent..?

moto raja
Ranch Hand

Joined: May 28, 2005
Posts: 55
Hi,

I am preparing for the SCWCD exam using the Head First Servlets book.

I need clarification why PUT is mentioned as idempotent.

The book mentions that GET is not supposed to change anything on the server and hence considered idempotent.
POST is non-idempotent because the data submitted thr' a POST is destined for some transaction that cant be reversed.

Now, PUT is used to put or store some data to the server, like a file to the server,doesnt it means it is changing something(the resources on the server,atleast) at the server, and hence , can be classified as non-idempotent?


Please let me know.

Thanks,
moritala.
Sergey Tyulkin
Ranch Hand

Joined: May 10, 2005
Posts: 87
Imagine you send TWO EQUAL requests to the server.
When you use POST, and the destination servlet adds (for example) a record to a database, based on the POST information, then you will add TWO records.
But if you use PUT then you will define on the server only ONE new resource, with the same content. The first request will create this resource, the second - replace just created resource with the same data, as the first resource (as the requests were EQUAL)
Priya Jothi
Ranch Hand

Joined: Jul 13, 2004
Posts: 168
Hi Kishore,

Can you refer to HFSJ book again?.If im not wrong i think post is a non-idempotent.I remember this only faintly not sure.Anyway i'll also refer & get back.

Idempotent : Multiple requests cause no side effects.

Non idempotent : Multiple requests may cause side effects.Business logic should take care of it.

If Post is considered as non-idempotent & post method is used then submitting the data which is present at the body would be updated in the server.If it is done more than once(by hitting the url more than once) this may cause side effect so it should be handled carefully.

Hope it is clear!!.

Regards,
Priya.
Priya Jothi
Ranch Hand

Joined: Jul 13, 2004
Posts: 168
Hi,

Sorry for my previous mail.I thought u r asking for a post method.Please ignore it.Neways i'll search for this question & get back shortly.

Regards,
Priya.
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

PUT is idempotent because the HTTP 1.1 spec defines it as idempotent. It is very logical. Practically we can define idempotent POST (doPost) method and non-idempotent GET (doGet) methods in Servlet, but it may treated as bad parctice.

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Rahul Sarup
Greenhorn

Joined: Jun 03, 2004
Posts: 4
Hi Ravi,

Here is what makes PUT idempotent.

IDEMPOTENT essentially means the ability of doing any operation again and again (i.e. more than once) without any side effects. This means every time you execute an idempotent operation, the outcome should be identical. It has nothing to do with what is changing on the server!

Since a particular PUT request will ALWAYS behave in the same manner, its idempotent!! The same is not true for a POST request.

I hope things are clear now..

Cheers !

Rahul

(The man on the Silver Mountain)
moto raja
Ranch Hand

Joined: May 28, 2005
Posts: 55
Your'e right, Rahul..


But I discovered a clash between HTTP1.1 spec and JSP2.4 spec...

HTTP1.1 spec says 'PUT,GET,HEAD are idempotent' , but
JSP2.4 spec says: " PUT NEED NOT BE IDEMPOTENT..." (;- I checked it ... )

However, dictionary meaning of idempotent : "used only once, even if used multiple times , without causing side effects.........." .. Going by that ,as u said ,PUT is idempotent ,as trying to put the same file twice will have no change on server state.....

Thnx guys for ur answers...
Ravi.
moto raja
Ranch Hand

Joined: May 28, 2005
Posts: 55
Oh, Guys, Now I feel I got it wrong about JSP2.4 spec..
It says PUT Need not be idempotent ...
I now understand what they meant is " the doPut() method in the servlet can be written in such a way that it can cause something else to happen" , not that the spec says "PUT IS IDEMPOTENT" .. Yeah, Sorry "SUN Micro...."
:roll:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Why is PUT considered as idempotent..?
 
Similar Threads
Idempotent request
IDEMPOTENT and NON-IDEMPOTENT
Why PUT is idempotent ?
which method is idempotent?
Why are 'PUT' and 'DELETE' considered idempotent?