Bookmark Topic Watch Topic
  • New Topic

doGet(req,res) within doPost()  RSS feed

 
saahil sinha
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • 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
 
Torsten Schippel
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Saahil,
the doGet method processes the data if you use METHOD="GET" (the default) to submit your HTML form data. doPost processes METHOD="POST" submissions.
doGet within doPost just means that independent of submission type the data will be processed by the same method. It just passes the data to the other method.
Regards
Torsten
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Report post to moderator
Also note that the GET method is default in the case that METHOD is not specified. Doing it this way will ensure that the doPost method of the servlet will be called which is where the heart of your code should be called. It is simular to implementing a method called doWork and having doGet and doPost both doWork. You do not have to do things this way. Just a matter of style.
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!