aspose file tools*
The moose likes JSP and the fly likes Why two methods GET and POST? Only one could serve the purpose Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Why two methods GET and POST? Only one could serve the purpose" Watch "Why two methods GET and POST? Only one could serve the purpose" New topic
Author

Why two methods GET and POST? Only one could serve the purpose

Snehal Bachchhav
Greenhorn

Joined: Nov 23, 2009
Posts: 4
Hi can any one please tel me why JSP Gives us Two Implementation for Service method ,Beside the difference of size of Submission of data n Security Why JSP gives us two Methods get n Post One Could have served the Purpose ?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

read this . and Please UseRealWords :)
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4466
    
    8

And note that this wasn't as decision made by the designers of JSP or Servlets. This is defined in the HTTP protocol, which is how the web works - any web programming language will support it in some way. There are more than two, although GET and POST are the most common - see Seetharaman's link for the complete list.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

Correct me if I'm wrong, but JSPs don't have two service methods, just one that's automatically generated. The JSP contents apart from declarations go in this method automatically. Servlets have 7 methods for servicing requests, including doGet and doPost.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Rob Spoor wrote:Correct me if I'm wrong, but JSPs don't have two service methods, just one that's automatically generated. The JSP contents apart from declarations go in this method automatically. Servlets have 7 methods for servicing requests, including doGet and doPost.


Correct. In the HttpServlet base class, the service() method examines the HTTP request type. It calls doGet() if the request is a GET request and doPost() is it's a POST request. Presumably some of the other request types are also dispatched as well, but I haven't checked lately.


Customer surveys are for companies who didn't pay proper attention to begin with.
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

Actually, HttpServlet gives you six do* methods:

doGet
doPost
doPut
doDelete
doOptions
doTrace

As was pointed out, these all represent methods of the underlying HTTP protocol. For many of my applications, both doGet and doPost simply turn around and call a custom "handleRequest" method I create, but if you're ever writing a servlet to handle REST ( http://en.wikipedia.org/wiki/REST ), those other methods suddenly become a lot more important!


OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

to try to answer briefly, why use post when you can use get. one is for short stuff the other is for longer stuff.


SCJP
Visit my download page
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

Randall Twede wrote:to try to answer briefly, why use post when you can use get. one is for short stuff the other is for longer stuff.

Not quite.

GET is for idempotent requests whose intent is to fetch the current state of a resource.

POST is for potentially non-idempotent requests whose intent is to perform an action.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

Pete Nelson wrote:Actually, Servlet gives you six do* methods:

doGet
doPost
doPut
doDelete
doOptions
doTrace

Almost right. First of all, Servlet gives you no do* methods at all. That's HttpServlet. Secondly, there is a 7th, doHead.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

Bear Bibeault wrote:
Randall Twede wrote:to try to answer briefly, why use post when you can use get. one is for short stuff the other is for longer stuff.

Not quite.

GET is for idempotent requests whose intent is to fetch the current state of a resource.

POST is for potentially non-idempotent requests whose intent is to perform an action.

I'd like to add that these rules are not as strict as that. GET has the limitation that all parameters go in the URL. That means that with many parameters, this URL becomes large; sometimes too large for the browser to handle (I've seen IE choke on a few myself). Also, all parameters are visible for the user. I myself find it justifiable to use POST for idempotent requests if the parameter list can become large or there is (semi) sensitive data in it.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

Right, things sometimes come to an engineering decision based upon limitations, but one should strive to follow the guidelines when possible.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why two methods GET and POST? Only one could serve the purpose