Difference between GenericServlet and HttpServlet

In this section we will discuss about the difference between GenericServlet and HttpServlet. GenericServlet is an abstract class that extends java.lang.Object while HttpServlet is an abstract class that extends GenericServlet.

Difference between GenericServlet and HttpServlet

In this section we will discuss about the difference between GenericServlet and HttpServlet. GenericServlet is an abstract class that extends java.lang.Object while HttpServlet is an abstract class that extends GenericServlet.

GenericServlet implements Servlet, ServletConfig and java.io.Serializable interfaces while HttpServlet implements java.io.Serializable.

HttpServlet is a subclass of GenericServlet and hence inherits its properties.

GenericServlet belongs to javax.servlet package while HttpServlet belongs to javax.servlet.http package.

HttpServlet has doGet(), doPost(), doPut(), doDelete(), init(), destroy(), getServletInfo() methods and one of them must be overridden. GenericServlet does not have doGet() and doPost() methods. GenericServlet requires HttpServlet for the support of these methods.

To write a  you need abstract service() to be overridden. A subclass of HttpServlet must override at least one method of doGet(), doPost(),doPut(), doDelete(), init(), destroy(), getServletInfo().

GenericServlet is a protocol-independent while HttpServlet is a protocol dependent. This means that GenericServlet can handle any types of protocol while HttpServlet can handle only HTTP specific protocol.