Difference between HttpServlet and GenericServlet

Last modified on July 27th, 2014 by Joe.

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

javax.servlet.http.HttpServlet
Signature: public abstract class HttpServlet extends GenericServlet implements java.io.Serializable

Comments on "Difference between HttpServlet and GenericServlet"

  1. parmar shaktisinh says:

    j2ee question available in site find out please

  2. robin says:

    the method that u have defined for servlet mapping is not correct. i am not satisfied with it.

  3. Anonymous says:

    aam voi saav tamne kai bhaan pade che ke nai su magaj nu dahi karo cho

  4. Pawan says:

    Your site is vary good.i am get more knowledge of your exa. Gernic and http servlet.

  5. SREEDHAR says:

    When httpservlet extends genericservlet——–> why httpservlet is not providing support for protocols other than http as parent class(genericServlet) supports FTP,SMTP….e.t.c..,

  6. Sheetal says:

    Your site is superb ..complete knowledge provider.

  7. B.Sreenivasarao says:

    What is the Basic difference between Servlet and Jsp.?

  8. Satish says:

    Again another article explained in a simple and sophisticated way.
    However, I would like to see details on service(). GenericServlet implements service() method from Servlet interface. HttpServlet extends that method. It first checks the method of form post in HTML form (GET/POST) and then delegates the processing to doGet() and doPost() methods. These can be (usually are) overriden. Am I correct?

    Still, great work Joe. I like your blog a lot.

  9. Rahul says:

    your faculty having less knowleadge about servlet and provides the basic knowleadge.

  10. Sushit Kumar says:

    Hey, this site is good.
    I m gaining more about java from this site.

    Keep it up…….

  11. ronak says:

    good

  12. Chetan Pagar says:

    Hello,

    It’s good content on your site… Specially I like the arrangement of content and website look..

    Regards
    Chetan Pagar

  13. PAWAN DWIVEDI says:

    thanks this is really a good effort i’m satisfied with your answer

  14. sv says:

    Generic servlet is a protocal independent, http is the propthe
    Protocal dependent(HTTP protocol), httpServlet is a
    sub class of Generic servlet, generic servlrt class
    is a abstract class because of service() is not not implemented in the generic servlet.IN httpServlet
    service methods has been implemented. 2 service
    methods are implemented in HTTP servlet one is

    public void service(ServletRequest,Servlet Response)
    another is
    protected void service(HTTPServletRequest,
    HttpServletResponse).

    So with out having the service() method, we can
    deploy the servlet in case of httpServlet.

    in case of GenericServlet with out having the service() method, we can not
    deploy the servlet .

  15. tuturanjan sahoo says:

    Generic servlet is a protocal independent, http is the propthe
    Protocal dependent(HTTP protocol), httpServlet is a
    sub class of Generic servlet, generic servlrt class
    is a abstract class because of service() is not not implemented in the generic servlet.IN httpServlet
    service methods has been implemented. 2 service
    methods are implemented in HTTP servlet one is

    public void service(ServletRequest,Servlet Response)
    another is
    protected void service(HTTPServletRequest,
    HttpServletResponse).

    So with out having the service() method, we can
    deploy the servlet in case of httpServlet.

    in case of GenericServlet with out having the service() method, we can not
    deploy the servlet .

    sv on June 15th, 2011 7:00 am

  16. tuturanjan sahoo,ABA,Balasore,Odisha says:

    What is the difference between GenericServlet and HttpServlet?
    GenericServlet is for servlets that might not use HTTP, like for instance FTP service.As of only Http is implemented completely in HttpServlet. The GenericServlet has a service() method that gets called when a client request is made. This means that it gets called by both incoming requests and the HTTP requests are given to the servlet as they are.

  17. Anonymous says:

    all questions are not truely……..

  18. vickky says:

    thanks buddy thats really helpfull 4 me

  19. captainportal says:

    good article
    its is a very important interview question in servlets

  20. Vikas says:

    Thanx dear…..
    Its a very impotant interview question and its very easy to set in my mind this topics……

  21. Nagraj says:

    Thanks for dis also

  22. Sachin says:

    This site is really great and authentic too…..

  23. mahesh says:

    this is helping me a lot thank you for keeping all these

  24. pankaj says:

    your solution is good but not the best as we expect from your side. please donot give us bookish knowledge tell what are happening inside the httpservlet and generic servlet.please sir elaborate the topic..

  25. Joe says:

    Pankaj,

    Agree that this is book type article. Still lot of people are finding it useful :)

    Let me see if I can add some more info to it.

  26. Apurv says:

    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:

    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 method of doGet(), doPost(),doPut(), doDelete(), init(), destroy(), getServletInfo()

  27. danie says:

    Nice one:-)

  28. sridhar says:

    Its really fantastic ….now i got a clear idea about the Genric and HttpServlet …thanks for your explanation…..:

  29. laxminarayana says:

    bad

  30. chandara says:

    I am not satiafied

  31. nagu says:

    1(a).this generic servlet class implements from servlet and servletconfig interfaces
    1(b).http servlet extended from generic servlet
    2(a)generic servlet overrides service()
    2(b)http is overrides anyone of 7 methods that are
    doGet(),doPost(),doPut(),delete(),init(),Destroy(),modify()
    3(a)session tracking possible from http only
    4(a)http is protocol dependent i.e only supports http
    4(b)generic is protocol independent

  32. neh says:

    nice one with good explanation!

  33. swopneel says:

    what is the use of Generic servlet class even though we have servlet interface

  34. sunil says:

    its nice…….

  35. Kavin says:

    That Cool…But needs some examples to explain that will be Good….

  36. AAR says:

    How To achive(I know session cant be used in Generic ) session in Generic servlet by using ftp protocal

  37. AAR says:

    How To achive(I know session cant be used in Generic ) session in Generic servlet by using ftp protocal

  38. Mallikarjun says:

    when GenericServlet implements Serializable, then what is the need to re-implement it in HttpServlet class?

  39. Anonymous says:

    hello
    please tell me

    when we send the request to server for servlet then is it http request or https request..?

  40. Anonymous says:

    please tell me the complete flow of http and htts ….

  41. Anonymous says:

    please tell me the complete flow of http and htts ….and etc

  42. pranavi says:

    ya this site is really good this site containing very useful information

  43. rahul says:

    great work joe..keep it up man

  44. Sonu Singh says:

    Your site is very good, it describe real language of servlet.

  45. Rafi says:

    So as per previous discussion,we can write a program with out having service() method,with using HTTP.can anyone explain clearly please

  46. Bhakti says:

    Thanks, Through this informations,
    students taking these informations &
    it is easy to write the Diff. bet.
    HttpSevlet & GenericServlet

    Thanks.

  47. ankita says:

    thank foe information that u had given in this blog….

  48. lavanya says:

    sir.it’s very useful.sir i have a problem that i am unable to insert data into the database by using jsp.can u help me out.i am using oracle.exe graphical mode for data base.can u help me out

  49. riaz Molwani says:

    http request is stateless when u sending request to server for servlet and server generate that response send back to the client then it break the connection btw client and server . ..

    the differnce is only only one S https what it does it secure that website means when eva u filling the form and entering the credit card # so plz first u look at the browser tht is there https if yes then it means its secure website
    thanks

  50. Anonymous says:

    i got lots of information…really very good site.

  51. Navin Prakash says:

    good for knowledge……

  52. ashok says:

    thnq bro..

  53. DPReddy says:

    why HttpServlet is declared as abstract?

  54. DPReddy says:

    There is no abstract methods in httpservlet then y it is abstract?

  55. Anonymous says:

    please upload that httpservlet class definition

  56. Rafi says:

    Hi,
    there are two methods in httpservlet..
    1.public void service(ServletRequest,Servlet Response)
    another is
    2.protected void service(HTTPServletRequest,
    HttpServletResponse)

    why do we require two methods and if there is a service method in HTTPSERVLET why we need of doxxx() methods.please let me know

  57. Anonymous says:

    why http servlet handle only http protocals?

    why genaric servlet handle any type of protocals?

    but differentiated of inheritances concept why?

  58. Anonymous says:

    give some more pointss

  59. anbu says:

    hii guys,
    why all user defined servlet classes extends HttpServlet? if anyone knows kindly reply?

  60. Anonymous says:

    thanks this type of information. we can know that diff. between generic servlet and http servlet…

  61. srinivas says:

    difference between protocol independent and protocol dependent

  62. shital bhayani says:

    i am satisfied with your comment.
    thank you.

  63. Anonymous says:

    sir,
    really it is very easy to understand thankyou sir…

  64. nn says:

    is genericServlet suppport http protocol

  65. anil says:

    Yes GenericServlet does support HTTP protocol.
    HttpServlet is protocol specific.

  66. jeelan says:

    this is the correct answer…

  67. gowtam says:

    what is given in above article is correct.what you have posted is wrong

  68. sai says:

    awsome your site is suprb matter also gd..

  69. Rajender says:

    —> GenericServlet can process multiple clients request from a single form. Whereas HttpServlet can process multiple clients requesting from multiple HTML forms.
    –> GenericServlet is Stateless and HttpServlet is Stateful.

  70. Lewis says:

    Servlet is basically a java code which can include html where as jsp is combination of java code and html.

  71. gopi says:

    ya u r given good explanation man.

  72. Anonymous says:

    thanks joe good one

  73. Vjosh says:

    Can you please check your last sentence ?
    GenericServlet is Stateless and HttpServlet is Stateful

    I think it should be Generic Servlet is stateful and http servlet is stateless.

    Correct me if i am wrong?

    looking forward for your reply ASAP

  74. Anonymous says:

    ok

  75. kiran says:

    if you develop your servlet useing servlet interface we must override all 5 methods in our servlet if these necessary are not.

    if you develop your servlet useing Genaric servlet we override only one sevice().

  76. pankaj jain says:

    Q. 1. – Can Generic servlet handle HTTP request also ?

    Q 2 . – Is Generic Servlet stateful if getting the non HTTP request ?

  77. Anonymous says:

    difference between inner class and outer class

  78. upendra says:

    u r right saying bro
    I am agree with u

  79. Rajeesh says:

    Hi Joe,

    I have been using javapapers for long time. Today, for a reference to Servlet/JSP related stuffs I came here. But with the new navigation/tree, I couldnt find out those topics anywhere in any of the folders here. At last I reached here by trying the topic with ‘javapapers’ on google. Could you please add all those missing ones from the old list(may be u have excluded it purposefully ) as well in tree of category so that we can ensure that we would not miss anything important like this :)

  80. manoranjan mishra says:

    Yes genericservlet can handle the http protol because it is protocl independent

    It can also handle smtp, ftp protol also

Comments are closed for "Difference between HttpServlet and GenericServlet".