• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

dopost within doget

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
}
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your replies.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic