Which method is overridden in servlet




















Are you sure you want to extend GenericServlet instead of HttpServlet? You should not be overriding the service method. Override doGet or doPost or both if you need to. If you have common code to execute for doGet and doPost then put it in a method and call that method from the doGet and doPost when you need to.

Thank you for your help!! I changed the code to as follows and it worked but it was not working earlier. Thanks a lot!! Tim Holloway. Saloon Keeper. S Majumder. Hi Abhimanyu, GenericServlet is a generic, protocol-independent servlet. Thanks , Satya. Appreciate the help and thank you for sharing the valuable knowledge. Because the routing takes place in service , you do not need to override service in an HTTP servlet.

Instead, override doGet , and doPost depending on the expected request type. The automatic routing in an HTTP servlet is based on a call to request. Override the service method for generic servlets or the doGet or doPost methods for HTTP servlets to perform tasks needed to answer the request. But when we extend HttpServlet to create a servlet then we cant override service as we need to override doGet or doPost method of HttpServlet.

Very unlikely. You should NOT override the service method. Yes, we can override service method. But then we have to give our own implementation to detect which type of method request is using.



0コメント

  • 1000 / 1000