how can we make a servlet to handle both GET and POST requests from html,is it possible?
GET and POST
Collapse
X
-
Tags: None
-
simply make a function, and call that from both doGet and doPost of the servlet.Originally posted by santoshmiraclehow can we make a servlet to handle both GET and POST requests from html,is it possible? -
Yes it is possible; quite a few Servlets simply make the method that handlesOriginally posted by santoshmiraclehow can we make a servlet to handle both GET and POST requests from html,is it possible?
the POST delegate to the method that handles the GET.
kind regards,
JosComment
-
But doGet and doPost methods extends service method and do all the preliminary tasks for HTTP GET and POST request, so calling them is a better approach.Originally posted by r035198xThere's also the service method for that kind of thing.Comment
-
I don't get what you mean by method extends another method. But I get the point that we are talking about HttpServlet here so overring the service method is not required and should not be done. The service method for HttpServlet knows which one to call between the doGet and doPost. To make them do the same thing then your method of making a separate method and calling it from both is probably best.Originally posted by sumittyagiBut doGet and doPost methods extends service method and do all the preliminary tasks for HTTP GET and POST request, so calling them is a better approach.Comment
-
Yea, you are right, I got lost, what I said about doGet and doPost is applicable for service method. I mean service method overrides generic service method, and do all the preliminary things about an HTTP request and calls the appropriate doXXX method. So we should not override service method, else we would have to do all the preliminary work ourselves.Originally posted by r035198xI don't get what you mean by method extends another method. But I get the point that we are talking about HttpServlet here so overring the service method is not required and should not be done. The service method for HttpServlet knows which one to call between the doGet and doPost. To make them do the same thing then your method of making a separate method and calling it from both is probably best.Comment
-
Or just insert a call to super.service()Originally posted by sumittyagiYea, you are right, I got lost, what I said about doGet and doPost is applicable for service method. I mean service method overrides generic service method, and do all the preliminary things about an HTTP request and calls the appropriate doXXX method. So we should not override service method, else we would have to do all the preliminary work ourselves.Comment
-
Yea, very true! (I forgot that option).Originally posted by r035198xOr just insert a call to super.service()Comment
Comment