jGuru
Register Email     Password Forgot your
password?
HOME FAQS FORUMS DOWNLOADS ARTICLES PEERSCOPE LEARN

  Search   jGuru Search Help

Question What is the difference between POST and GET methods? What about PUT, DELETE, TRACE, OPTIONS, and HEAD?
Derived from A question posed by Amisha Patel
Topics Java:API:Servlets
Author Simon Brown
Created May 25, 2000 Modified Aug 10, 2000


Answer
GET and POST basically allow information to be sent back to the webserver from a browser (or other HTTP client for that matter).

Imagine that you have a form on a HTML page and clicking the "submit" button sends the data in the form back to the server, as "name=value" pairs.

Choosing GET as the "method" will append all of the data to the URL and it will show up in the URL bar of your browser. The amount of information you can send back using a GET is restricted as URLs can only be 1024 characters.

A POST on the other hand will (typically) send the information through a socket back to the webserver and it won't show up in the URL bar. You can send much more information to the server this way - and it's not restricted to textual data either. It is possible to send files and even binary data such as serialized Java objects!

A PUT allows you to "put" (upload) a resource (file) on to a webserver so that it be found under a specified URI. DELETE allows you to delete a resource (file). These are both additions to HTTP/1.1 and are not usually used. HEAD returns just the HTTP headers for a resource. TRACE and OPTIONS are also HTTP/1.1 additions and also rarely used.

The Servlet spec allows you to implement separate Java methods implementing each HTTP method in your subclass of HttpServlet. Override the doGet() and/or doPost() method to provide normal servlet functionality. Override doPut() or doDelete() if you want to implement these methods. There's no need to override doOptions() or doTrace(). And the superclass handles the HEAD method all on its own.

The full specs for HTTP are available (if you're interested) can be found on the w3c.org site. See also the JavaDoc for HttpServlet.

[Edited/enhanced by Alex]

See also:



Is this item helpful?  yes  no     Previous votes   Yes: 8  No: 0



Comments and alternative answers

Comment on this FAQ entry

HTTP POST and HTTP GET
shailesh patel, Feb 9, 2010
Here is the good article that explains HTTP POST and HTTP GET method. http://patelshailesh.com/index.php/http-get-and-http-post-in-asp-net

Is this item helpful?  yes  no     Previous votes   Yes: 0  No: 0



Reply to this answer/comment  Help  


Ask A Question



 
Related Links

Servlets FAQ

Servlets Forum

Servlet-related resource list from Purple Technology

jGuru JSP FAQ

Sun Servlet Home Page

Wish List
Features
About jGuru
Contact Us

 



The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers