• Post Reply Bookmark Topic Watch Topic
  • New Topic

doGet(req,res) within doPost()

 
saahil sinha
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I have seen a no. of codes for servlet where they have the doGet()implemented with some logic and in the doPost() has this within it doGet(req,res).Why is this required and what is its function within the code.Pls help
 
Panagiotis Varlagas
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. doGet() and doPost() get invoked by the service() method according to whether the HTTP request is a GET or a POST one. There are some cases where we want the servlet to handle GETs and POSTs in exactly the same manner.
An approach to this (which I like the most) is to write a method named (say) performTask() that does the actual work and have doGet and doPost call that one. Some people follow an alternative approach code either doGet or doPost and then have the one code the other.
... doGet(...) {
doPost(...);
}
This is essentially like telling the servlet container: "In the case of a GET request, do the same as in the case of a POST request".
Nothing more, nothing less.
Hope this helps,
Panagiotis.
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"performTask"? Do we still have VisualAge people out there?
 
Panagiotis Varlagas
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep. I'm an old VAJ guy...
But using WSAD since early 2002.
[ June 22, 2003: Message edited by: Panagiotis Varlagas ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!