| Author |
doGet(), doPost() implementation
|
Vishwa Kumba
Ranch Hand
Joined: Aug 27, 2003
Posts: 1064
|
|
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
Joined: Sep 18, 2003
Posts: 5
|
|
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
Joined: Aug 27, 2003
Posts: 1064
|
|
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
Joined: Oct 27, 2003
Posts: 90
|
|
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
|
SCJP 1.4, SCJD, SCWCD 1.4
|
 |
Harish Yerneni
Ranch Hand
Joined: Sep 15, 2004
Posts: 94
|
|
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
|
SCJP 1.4 | SCWCD 1.4 | SCJD (WIP)
|
 |
Stephen Galbraith
Ranch Hand
Joined: Oct 27, 2003
Posts: 90
|
|
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
Joined: Aug 27, 2003
Posts: 1064
|
|
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
Joined: Oct 27, 2003
Posts: 90
|
|
Thought so, thanks for the confirmation. Steve
|
 |
Harish Yerneni
Ranch Hand
Joined: Sep 15, 2004
Posts: 94
|
|
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.
|
 |
 |
|
|
subject: doGet(), doPost() implementation
|
|
|