Home Java Beginners Difference between GenericServlet and HttpServlet
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Difference between GenericServlet and HttpServlet

Advertisement
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.

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.

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 14, 2013

Ask Questions?    Discuss: Difference between GenericServlet and HttpServlet  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com