0

I have used POST for inserting record and PUT for updating record when handling REST webservice, but with respect to the Http Servlet what is the difference between the post and put method and when do you use put method?

Arvind
  • 199
  • 1
  • 5
  • 1
    PUT/POST are HTTP protocol methods. http://stackoverflow.com/questions/630453/put-vs-post-in-rest – kosa Oct 30 '13 at 04:17
  • 1
    You may consider reading REST and read about the verbs associated with HTTP. – yadab Oct 30 '13 at 04:34

2 Answers2

3

HttpServlet follow the HTTP specs as well which in simpler terms says:

POST: To create a resource

PUT: To modify a resource and if resource does not exist then create it

HttpServlet provides an implementation of POST and PUT in doPost and doPut method.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • It might be worth adding that the linked HTTP spec has detailed expectations for `POST` and `PUT`, answering the second half of the question. – bstempi Oct 30 '13 at 04:25
  • @bstempi The link is already there in the first sentence, let me make it bold :-) – Juned Ahsan Oct 30 '13 at 04:27
  • Your answer confuses entities and resources. The wording in the RFC you cited is greatly to be preferred. – user207421 Oct 30 '13 at 04:38
  • @EJP Modified the answer, hope it is inline with specs now. Feel free to do any required modifications. Thanks for pointing it out. – Juned Ahsan Oct 30 '13 at 04:40
0

According to JavaDocs...

HTTP POST method allows the client to send data of unlimited length to the Web server a single time and is useful when posting information such as credit card numbers.

PUT operation allows a client to place a file on the server and is similar to sending a file by FTP.

hope it helps.

Ashish
  • 735
  • 1
  • 6
  • 15