What is the difference between GenericServlet and HttpServlet?

Solution

javax.servlet.GenericServlet

Signature

public abstract class GenericServlet extends java.lang.Object implements Servlet, ServletConfig, java.io.Serializable

  • Generic Servlet is protocol independent.It handles all types  of protocol  like http, smtp, ftp etc.
  • GenericServlet gives a blueprint and makes writing servlet easier.
  • GenericServlet provides simple versions of the life-cycle methods init and destroy and of the methods in the ServletConfig interface.
  • GenericServlet implements the log method, declared in the ServletContext interface.
  • To write a generic servlet, it is sufficient to override the abstract service() method.

javax.servlet.http.HttpServlet

Signature

public abstract class HttpServlet extends GenericServlet implements java.io.Serializable

  • HttpServlet defines a HTTP protocol specific servlet.
  • HttpServlet gives a blueprint for Http servlet and makes writing them easier.
  • HttpServlet extends the GenericServlet and hence inherits the properties GenericServlet.

Share this thread

Comments

Comments
comments powered by Disqus

Navigation

Social Media