File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Snehal Bachchhav
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
read this . and Please UseRealWords :)
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17620
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Randall Twede
Ranch Hand
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to try to answer briefly, why use post when you can use get. one is for short stuff the other is for longer stuff.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, things sometimes come to an engineering decision based upon limitations, but one should strive to follow the guidelines when possible.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic