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

doGet() or doPost() ?

Vishakha Ahuja
Ranch Hand

Joined: Sep 13, 2000
Posts: 191
How do I know, which of the 2 methods: doGet() or doPost() should I override in my servlet class ?
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

In the good olden days, it was said like this.
regds.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Vishakha Ahuja
Ranch Hand

Joined: Sep 13, 2000
Posts: 191
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?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
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.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Sowmya Vinay
Greenhorn

Joined: Feb 01, 2001
Posts: 24
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.
Brett Knapik
Ranch Hand

Joined: Oct 15, 2000
Posts: 255
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....


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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).]


SCJP
Visit my download page
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doGet() or doPost() ?