This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doGet() or doPost() ?

 
Vishakha Ahuja
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I know, which of the 2 methods: doGet() or doPost() should I override in my servlet class ?
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • 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.
 
Sowmya Vinay
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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.
 
Brett Knapik
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • 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....
 
Randall Twede
Ranch Hand
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • 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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic