This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dopost within doget

 
Deepthi Katta
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a loginservlet that validates the user information entered in a html form against that contained in database.
In that servlet there is a doget method that calls dopost. And all the processing is done in dopost. I don't understand what the purpose of this is. can anyone help me out?
The code is like this:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
//Processing done here
}
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
probably you want it to work for both the kind of requests
GET / POST.
Normally i guess people write the processing code in the
service() method from GenericServlet class whuch gets called before the doGet/ doPost methds.
(rather override it in their code)
karthik.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Overriding the service method is normally not a good idea. the service method provided with HTTPServlet does clever things with other request types (HEAD, OPTIONS etc.). If you override service in your own servlet and assume the only request types you will see are GET and POST you are mistaken and will sometimes get wierd and unexpected behaviour.
It is a much better solution to only override the request types you are interested in (typically GET and POST, occasionally HEAD). There are two ways of doing this. One is as mentioned above - call doPost from doGet (or vice versa). The other is to create an entirely new method (eg. "doAll") and call that from both doPost and doGet.
 
Deepthi Katta
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your replies.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic