Difference Between GenericServlet and HttpServlet

Difference Between GenericServlet and HttpServlet in Tabular Form

GenericServlet and HttpServlet Difference




  • The Key difference between GenericServlet and HttpServlet is that the GenericServlet is protocol independent and whereas HttpServlet is protocol dependent.
  • GenericServlet belongs to javax.servlet.GenericServlet package while HttpServlet belongs to javax.servlet.http.HttpServlet package.
GenericServlet and HttpServlet
GenericServlet and HttpServlet

GenericServlet and HttpServlet Comparison Chart

GenericServlet HttpServlet
It is defined by javax.servlet package. It is defined by javax.servlethttp package.
It describes protocol-independent servlet It describes protocol-dependent servlet.
GenericServiet is not dependent on any particular protocol. It can be used with any protocol such as HTTP, SMTP, FTP, and so on. HttpServlet is a dependent protocol and is only used with HTTP protocol.
All methods are concrete except the service() method. service() method is an abstract method. All methods are concrete (non-abstract). service() is non-abstract method. service() can be replaced by doGet() or doPost() methods.
The service method is abstract. The service method is non-abstract
It forwards and includes a request and is also possible to redirect a request. It forwards and includes a request but it is not possible to redirect the request.
GenericServlet doesn’t allow session management with cookies and HTTP sessions. HTTPServlet allows session management with cookies and HTTP sessions.
It is an immediate child class of Servlet interface. It is an immediate child class of GenericServlet class.
GenericServlet is a superclass of HttpServlet class. HttpServlet is a subclass of GenericServlet class.




More Difference