File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Get And Post Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Get And Post" Watch "Get And Post" New topic
Author

Get And Post

surya chintalapudi
Greenhorn

Joined: Sep 13, 2012
Posts: 9
i have a small doubt in servlets...in which seniors we use get and post methods...please don't say differences(when we use commandlink on webpage...in that scenarios we use get only)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You should use the GET method when the request is intended to get information from the server, without changing its state. You should use the POST method when the request is intended to send information to the server and change the server's state.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

Paul Clapham wrote:You should use the GET method when the request is intended to get information from the server, without changing its state. You should use the POST method when the request is intended to send information to the server and change the server's state.


That's an interesting philosphy, but I'd think it conflicts with REST, which is supposed to be GET-based. Also with forms using "action=GET" instead of "action=POST".

More formally, the HTTP GET is intended for resource access (which in J2EE includes servlet logic invocation) where the URL is self-contained. Which is isn't really, since all those headers and cookies and stuff are also tagging along.

HTTP POST, however, is designed for uploading large volumes of data external to the URL proper. Especially MIME-encoded large objects such as file uploads.

In some clients or servers, URLs have to be less than a few thousand characters, so GET requests cannot be used for uploading large amounts of data or forms with a lot of data in them.

Another difference is that GET URLs can be bookmarked. Most web clients don't have a place to store the out-of-band data that POST uploads, so you can't properly bookmark POSTs.


Customer surveys are for companies who didn't pay proper attention to begin with.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

Tim Holloway wrote:
Paul Clapham wrote:You should use the GET method when the request is intended to get information from the server, without changing its state. You should use the POST method when the request is intended to send information to the server and change the server's state.


That's an interesting philosphy, but I'd think it conflicts with REST, which is supposed to be GET-based.


Doesn't REST use serveral HTTP verbs typically? GET is used to get information about the resource, but POST, PUT and DELETE are used to change state. Which would match what Paul is saying. Or am I misunderstanding what you're trying to say?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

I am not a REST expert. The Wikipedia entry confuses me, since they talk about REST being stateful on the server, and stateless on the client, and I always looked at it the other way around, with the advantage of stateless servers being that A) they didn't need to maintain a separate set of session data for each connected client (and could therefore scale better) and B) there was no inherent binding of a client to a particular server. So you could load-balance without worrying about transferring state between the servers.

Using GET instead of POST is mostly predicated on the idea that GETs are smaller than POSTS and that if you're not transferring state back and forth between client and server, you shouldn't need to use POST in most instances. But YMMV.

Also, I tend to think of REST as a solution to "one-off" queries and therefore something worth bookmarking, but that's mostly just me.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

I think it means stateful on the server as in there is a resource with a particular state, not that there's a state associated with a particular client.

The stuff I've read about REST (also not an expert) talked about the "uniform interface" that's an important part of the concept, which in terms of RESTful web services means using HTTP as an application protocol as well as a transfer protocol - so you use the meanings of the HTTP verbs and response codes. Representational_state_transfer#RESTful_web_services matches what I've come across in other places.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Using GET instead of POST is mostly predicated on the idea that GETs are smaller than POSTS and that if you're not transferring state back and forth between client and server, you shouldn't need to use POST in most instances. But YMMV.


Not really - in strict REST architecture, GET retrieves the current state of a resource without modifying it, ie it is idempotent. Think a static image or current stock price.

POST modifies the resource - such as a "shopping cart"

There is an excellent list of further resources on the ranch WebServicesFAQ page.

Bill

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

REST uses all methods: GET, POST, DELETE, and UPDATE (and even HEAD).

In no way, shape, or form is REST "GET-based".


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I am not a REST expert either. Which is why my answer was based on what we see in standard HTML-based web applications, i.e. GET and POST are the only options in actual use. And I suspect the question was based on that assumption as well.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Agreed since this is asked in relation to servlets. In that case, Paul's first reply is the correct answer: GETs for gets, POSTs for operations.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get And Post
 
Similar Threads
when to use get method versus post method in the servlet?
Disable Url
Using GET other than POST
HTML get and post method?
About jsessionid