What is the difference between GenericServlet, HttpServlet and a Servlet?

前端 未结 10 1715
抹茶落季
抹茶落季 2020-12-23 15:16

I was searching for exact difference between javax.servlet.http.HttpServlet , javax.servlet.GenericServlet and javax.Servlet unable to

10条回答
  •  [愿得一人]
    2020-12-23 15:34

    Servlet is an interface which contains five abstract methods in order use servlet we have to provide an implementation for all these five methods, which is a headache. In order to avoid this complexity, we have GenericServlet and HttpServlet for next level.

    GenericServlet is protocol independent, it means it can accept any protocol request. GenericServlet can forward and include a request but we can not redirect the request. Session Management with cookies and HttpSession is not possible in GenericServlet. In GenericServlet it is not possible to define separate logic for get and post request.

    HttpServlet is protocol dependent. it means, it accepts only HTTP protocol request. HttpServlet can forward and include and redirect a request. Session Management with cookies and HttpSession is possible in HttpServlet. In HttpServlet it is possible to define separate logic for get and post request.

提交回复
热议问题