Difference Between GenericServlet and HttpServlet?

Generic Servlet:
  • GenericServlet class is direct subclass of Servlet interface.
  • Generic Servlet is protocol independent.It handles all types  of protocol  like http, smtp, ftp etc.
  • Generic Servlet only supports  service() method.It handles only simple request 
    public void service(ServletRequest req,ServletResponse res ).
  • Generic Servlet only supports  service() method.
HttpServlet:
  • HttpServlet class is the direct subclass of Generic Servlet.
  • HttpServlet is protocol dependent. It handles only http protocol.
  • HttpServlet  supports public void service(ServletRequest req,ServletResponse res ) and protected void service(HttpServletRequest req,HttpServletResponse res).
  • HttpServlet supports also   doGet(),doPost(),doPut(),doDelete(),doHead(),doTrace(),doOptions()etc.

33 comments :

  1. thanks all for valuable feedback

    ReplyDelete
  2. Hi

    Does GenericServlet have Stateless Nature or Stateful Nature?
    As i know HttpServlet does have a stateless Nature due to http protocol?

    Please guide me as i am a new bee in servlet..

    ReplyDelete
  3. Hi it depends which type of protocol is being used with GenericServlet class as it is protocol independent and we can send request to GenericServlet class Using HTTP, FTP and SMTP.

    ReplyDelete
  4. Hi
    In GenericServlet class we can also use
    service(HttpServletRequest request, HttpServletResponse response)
    I have seen examples using service methods as is
    is it true ??

    ReplyDelete
    Replies
    1. It is not correct to use httpservlet request & response in generic servlet

      Delete
  5. very Good man, thanks any doubts cal to this number i am all so S\w Engg. java develaper pls cal to me , this is my number(9154421946. AP, india

    ReplyDelete
  6. avax.servlet.GenericServlet
    Signature: public abstract class GenericServlet extends java.lang.Object implements Servlet, ServletConfig, java.io.Serializable

    GenericServlet defines a generic, protocol-independent servlet.
    GenericServlet gives a blueprint and makes writing servlet easier.
    GenericServlet provides simple versions of the lifecycle 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.

    ReplyDelete
  7. core java, jdbc, jsp,servlet,spring, web services Hibernate, struts

    ReplyDelete
  8. nice answer

    ReplyDelete
  9. Good Explanation................

    ReplyDelete
  10. However there are some exemptions for which the landowner will not be held accountable, such
    as: any kind of flue which is connected to the gas appliance which is owned personally by the
    landowner or by the tenant. The driver's licensing exams in all stated require that drivers pass a vision test, but
    they do nothing to test for reaction speed. It helps an individual in knowing the amount he has
    to pay or expect while buying or selling the real estate respectively.


    Stop by my web page; newspaperarchive

    ReplyDelete
  11. though GenericServlet is protocol-independent servlet, so can we call a GenericServlet using SMTP or FTP, etc protocalls..?

    ReplyDelete
  12. thnks to all .............v good ans.

    ReplyDelete
  13. not bad why we are using doXXX() methods

    ReplyDelete
  14. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete
  15. I wish to show thanks to you just for bailing me out of this particular
    trouble.As a result of checking through the net and meeting
    techniques that were not productive, I thought my life was done.


    java Training in Bangalore



    java training in chennai

    ReplyDelete

  16. The information that you shared with us is very useful and thanks for sharing. Also, many thanks for permitting me to comment!

    Quicken Support Number

    Quicken Online Support Number

    Quicken tech Support Number

    HP Support Number

    ReplyDelete