Should I override service() or doPost()?

后端 未结 5 2079
余生分开走
余生分开走 2021-01-04 08:53

I was reading a book on servlets, in that book a brief explanation is given about the servlet class, as well as the HttpServlet class.

There is one exam

5条回答
  •  庸人自扰
    2021-01-04 09:34

    I think you need to understand the flow in order to decide for yourself. The default implementation of service() for an HttpServlet simply calls the appropriate handler for the request method (GET, POST, whatever).

    You need to override service() when you want the same method to handle all incoming methods (no matter if it's a GET, PUT or POST request, you'll answer the same to all). If you're happy with treating each method separately, go with the default service() implementation and override the specific handlers.

提交回复
热议问题