Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

doGet(), doPost() implementation

 
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
 
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.
 
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
 
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.
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic