• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doGet(), doPost() implementation

 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HF book, chapter 4, p:118...at the bottom of the page, it says....

Developers who want to support both methods usually put logic in doPost(), then delegate to a doGet() if this request doesn't need to do post things
[CODE]
public void doPost(...) {
throws ...
doGet(request, response);
}[/CODE


I didn't understand. Can somebody elaborate this?
Why not the other way around? (doPost() inside a doGet() method())

thanks,
Vishwa
 
vykuntam chandra sekhar rao
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vishva i too think this is other way ...

in doGet() and doPost() call a common function to implement ie
doGet(req,res){
common(req,res);
}

doPost(req,res){
common(req,res);
}


and in common we can write businness logic .
if possible correct any one.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chandra,
thanks for the suggestion, but what I meant was.....


i.e, assuming that you have all ur implementation in doPost(). I was wondering whether the above is also acceptable.
 
Stephen Galbraith
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it depends what you mean by acceptable.

I wonder if they suggest the mechanism the way round that they do because doPost can be non-idempotent whereas doGet is supposed to be idempotent (I say supposed because you can make either non-idempotent/idempotent it's up to you as the coder).

This would mean that if doGet called doPost then we have a break down in what we are supposed to guaranting in the spec, whereas the other way around we are not.

Sound valid?

Steve
 
Harish Yerneni
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishwa...you are correct.

It is posted correctly in the errata.

Here is the link for errata

http://www.oreilly.com/catalog/headservletsjsp/errata/.

Hope this helps!

Harish
 
Stephen Galbraith
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The errata says
"A: Developers who want to support both methods usually put
logic in doGet(), and then have the doPost() implementation delegate to that doGet():"


now I think that would then be ...


and not


and I think that it is this way around because of the idempotency issue, but I'd like your opinion.

Steve
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harish: thanks for the errata link. Yes, the wordings in the sentence are not clear.

Stefan: Yes, the recommended is still the same.
public void doPost(...) {
doGet(...);
}

If we ignore the idempotency vocab for a minute and use a layman's language like mine:

doGet() - read method
doPost() - write method

The recommended is :

public void writeMethod() {
calling readMethod();
}

and not

public void readMethod() {
calling writeMethod();
}

But why?...A write method can do both write and read operations, but while read method is supposed to do only a read operation?
 
Stephen Galbraith
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thought so, thanks for the confirmation.

Steve
 
Harish Yerneni
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thought to share...

By default, a simple hyperlink uses HTTP GET method and looks for doGet() implementation in the servlet. So

doGet()
{

doPost(){}

}

is more safe.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic