Hi,
what is the difference between GenericServlet and HttpServlet in java ?
Generic Servlet and http Servlet in java
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Oct 22, 2011, 9:23 AM EDT
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