Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

dopost within doget

 
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
}
 
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.
 
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.
 
Yup, yup, yup. Tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic