• Post Reply Bookmark Topic Watch Topic
  • New Topic

doPost and doGet  RSS feed

 
Eric Lidell
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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?
 
Gary Mann
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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().
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!