• Post Reply Bookmark Topic Watch Topic
  • New Topic

doPut(), why we have this method?

 
Praveen Kumar Singh
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys

I have uploaded diffrent files, many times with doPost method(in normal servlet and in spring), but i never noticed the fact that we have a method call doPut() whose whole purpose is to put a file on server side but still we never use it.
Any one please put some light on it !!

Praveen
SCJP,SCWCD,SOA
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
remember that the HTTP spec is very old and was initially designed to do things with different aims in mind.
You are correct that POST is typically used, but GET is often used when POST should be used.
There is often a bit of flexibility.
 
Praveen Kumar Singh
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David

Thanks for replay, and i agree that http spec is old but if you read the w3c http article, nothing is written that PUT method should not be use or we should avoid to use it.
Actually PUT is still very famous at non-servlet area like REST and MULE(i mean in Web-Service domain) and still the part of HTTP 1.1 and servlet 1.5 spec

Do you have any information why and when not to use PUT method or in other words why to use POST?


 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PUT is initially not intended to put a full file on server side.
PUT requires request parameters been passed through the URL (like as GET). You can't put a file in there.
POST offers roughly the same as PUT but adds some more flexibility, which is the main reason why POST is preferred.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65518
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTTP is used for more than just browser-based pages. The browsers do not support PUT, but it's a very important method for web services.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I googled a bit and found this interesting article: http://www.cwinters.com/blog/2006/06/16/put_vs_post.html
Also keep in mind that some webbrowsers apparently doesn't correctly support PUT.

Just use POST or GET. Use GET for request preprocessing or for idempotent (bookmarkable) requests and use POST for request postprocessing.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what the relevant standard - RFC 2616 says

9.6 PUT

The PUT method requests that the enclosed entity be stored under the
supplied Request-URI. If the Request-URI refers to an already
existing resource, the enclosed entity SHOULD be considered as a
modified version of the one residing on the origin server.


Therefore it is incorrect to state that PUT is "not intended to put a full file on server side."

The entry for POST is:

9.5 POST

The POST method is used to request that the origin server accept the
entity enclosed in the request as a new subordinate of the resource
identified by the Request-URI in the Request-Line. POST is designed
to allow a uniform method to cover the following functions:

- Annotation of existing resources;

- Posting a message to a bulletin board, newsgroup, mailing list,
or similar group of articles;

- Providing a block of data, such as the result of submitting a
form, to a data-handling process;

- Extending a database through an append operation.


A google search for rfc2616 will get you the full text of Hypertext Transfer Protocol -- HTTP/1.1

bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!