File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes GET or POST? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "GET or POST?" Watch "GET or POST?" New topic
Author

GET or POST?

Ryan McClain
Ranch Hand

Joined: Nov 27, 2010
Posts: 95
(I am referring to the book 'Head First Servlets & JSP', page 19 (page 53 in the PDF))

Which HTTP method (GET or POST) would best be invoked when the following use cases take place?
a) A user hits the 'back' button on the browser.
b) A user makes a radio button selection on an HTML form.

I am doubting about a), because that would be technically telling the browser to do the command historyArray.getPreviousPage() and no GET command or even the HTTP protocol would be involved - just the browser's internal API.
I'm not sure if a GET is involved in there.

As for b), I don't think it's very resource efficient to be sending a POST to the server at the moment the user checks a radio button. Of course, modern web applications use AJAX for this but I'm not sure if POST would be used there.
Would it be possible that the answer could be 'neither GET nor POST'?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5

A. will certainly be a GET if the browser is designed that way since all it keeps in history is the URL.

B. The intent for the HTTP POST method is to modify a resource - certainly appropriate for making a selection in a form but note that simply modifying any form element does NOT normally cause submission of the form. That would take a submit button or JavaScript/AJAX specifically programmed.

Your FORM options are GET or POST only.

Bill
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

b) is not answerable without knowing the intent of the request. Is it intended to merely fetch a resource? Or to "do something"?

Another way to look at it: is the result of hitting the button the same response, again, and again, and again? If not, then it's not a GET. GETs must be idempotent.

Note that the inverse is not always true: a request that results in the same response each time doesn't have to be a GET. Again, depends upon intent.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ryan McClain
Ranch Hand

Joined: Nov 27, 2010
Posts: 95
William Brogden wrote:
A. will certainly be a GET if the browser is designed that way since all it keeps in history is the URL.
...
Bill

Do (modern) browsers (Chrome?) not fetch the pages from cache once they have been visited (to speed things up)? I think I recall reading on stackoverflow that a GET is not even issued after the browser decides to go cache mode.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Not all pages are cached. In fact, most in a web app aren't (or shouldn't be).
Ryan McClain
Ranch Hand

Joined: Nov 27, 2010
Posts: 95
Bear Bibeault wrote:Not all pages are cached. In fact, most in a web app aren't (or shouldn't be).

Last year when I was developing a business app I had a lot of problems with caching in Chrome, so I had to turn it off.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GET or POST?
 
Similar Threads
get or post
Which request is better Get or Post?
Struts 1.1: html:radio issues
Doubt in HFSJ, page 19
Disabling back button in the browser