This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

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

 
Greenhorn
Posts: 4
  • 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 ?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
read this . and Please UseRealWords :)
 
Bartender
Posts: 4568
9
  • 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.
 
Sheriff
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • 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.
 
Saloon Keeper
Posts: 21269
138
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • 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.
 
Ranch Hand
Posts: 147
Eclipse IDE Tomcat Server Debian
  • 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!
 
Ranch Hand
Posts: 4702
9
Scala Java
  • 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.
 
Marshal
Posts: 67300
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 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
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • 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
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • 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
Marshal
Posts: 67300
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 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.
 
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!