Hi,
what is the difference between GenericServlet and HttpServlet in java ?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Oct 22, 2011, 1:23 PM
Generic servlet is Protocol independent.
HTTP Servlet is protocol dependent Generic Servlet does not contain doGet() and doPost() methods,you have to provide your own implementation of doGet() and doPost() methods where as HttpServlet has got doGet() and doPost() methods which you have to override in your implemented class
Generic Servlet has init() method whereas Httpservlet doesnot have.and Generic Servlet is the super class of theHttpServlet.
GenericServlet belongs to javax.servlet package GenericServlet is an abstract class which extends Object and implements Servlet, ServletConfig and java.io.Serializable interfaces.
The direct subclass to GenericServlet is HttpServlet.It is a protocol-independent servlet.To write a GenericServlet you need abstract service() to be overridden.
HttpServlet belongs to javax.servlet.http package This is an abstract class which extends GenericServlet and implements java.io.Serializable
A subclass of HttpServlet must override at least one methodof doGet(), doPost(),doPut(), doDelete(), init(), destroy(),getServletInfo()
A GenericServlet has a service() method aimed to handle requests. HttpServlet extends GenericServlet and adds support for doGet(), doPost().
Thanks