• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why is PUT considered as idempotent..?

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic