• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

doGet() or doPost() ?

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I know, which of the 2 methods: doGet() or doPost() should I override in my servlet class ?
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In the good olden days, it was said like this.
regds.
- satya
 
Vishakha Ahuja
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Now, I do understand the difference b/w form's GET and POST methods, but when it comes to servlets, I've seen doPost() just calls the doGet() (the book is Marty Hall's Core Servlets and JSP). If that is the case, why have 2 diff. methods ? I mean shouldn't they have different purposes?
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The two methods are there because they represent two different HTTP requests (there are also doHead(), doOptions() etc, but they are rarely used). If your application needs to give the same response to both POST and GET requests, then setting one to call th eother is a reasonable way to do it.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vishakha Ahuja:
Hi,
Now, I do understand the difference b/w form's GET and POST methods, but when it comes to servlets, I've seen doPost() just calls the doGet() (the book is Marty Hall's Core Servlets and JSP). If that is the case, why have 2 diff. methods ? I mean shouldn't they have different purposes?



The book you mentioned"Core servlets and JSP" by Marty Hall has clearly described the 2 methods and their relevance. Please go through the JSP section once again to get a clear understanding.
 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Get and post methods can be used for security. Lets say that you have a shopping cart application if you use the get response when the user enters their credit card it will be in the browser bar leading to hackers for CC information. If you use a post you are safe just as long as you are in SSL.
------------------
In Gates we trust. Yeah right....
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I prefer using Post when I can because of what Brett said. Also if you use doGet() the person can bookmark the page, with doPost() they cant. doGet is the only way to call a servlet from a
<a href so it is very useful in that way.

[This message has been edited by Randall Twede (edited March 07, 2001).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic