• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

doPost and doGet

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The basic convention in servlets extending HttpServlet is define one of the methods doGet or doPost (in case both happen to have the same processing logic) and call the other from inside the container called one.for eg:
class myservlet extends HttpServlet{
public void doGet(HttpRequest req,HttpResponse resp){
lots of code
}
public void doPost(HttpRequest req,HttpResponse resp){
doGet( req,resp);
}

}
Thats the above convention.My question is which is advantageous?
Defining code inside doPost and calling doPost from doGet request or defining code inside doGet and calling doGet from doPost ?
and Why?
is there any thumb of rule or justification for it?
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you always want the two methods to act the same way, the it doesn't matter which one calls which. An alternative is to create a third method that contains the common logic and call the method from both doGet() and doPost().
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There may be times you don't want get & post to do the same logic. Maybe you want to allow users to post a form to do something, but not allow them to compose a bookmarkable url to do the same thing. Maybe all gets return static content and all posts run actual programs. Does that sound right?
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gray Man,
Welcome to JavaRanch!! Please change your name to be compliant with JavaRanch's naming policy. It should not be obviously fictitious.
Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name.
You can change your name: here.
Thanks,
Cindy
 
Eric Lidell
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the replies.
I understand the scenario for when post and get do occur.
i wanted a scenario where they process the same logic.
Thanks a lot.
I thought there would be some advantage in calling.
I guess there isnt
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic