Difference between HttpServlet and GenericServlet

14/05/2008

javax.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.

j2ee question available in site find out please

parmar shaktisinh on June 30th, 2010 4:43 pm

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

robin on July 13th, 2010 12:04 am

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

Anonymous on August 18th, 2010 10:09 am

you are rong buddy the above method which definded by you that all the method are rong yaar

firt diffrance

http is protocol dependent
genric is protocol indipendent

http use service() method to handle request
genric use doGet() or doPost() method to handle request

http support cookie session url Rewriting while
genric does not support

so pls change above method which is definded by you ok

one & only Hiren Modi on August 18th, 2010 10:13 am

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

Pawan on October 31st, 2010 3:47 am

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..,

SREEDHAR on November 9th, 2010 11:47 pm

Your site is superb ..complete knowledge provider.

Sheetal on November 27th, 2010 3:40 am

What is the Basic difference between Servlet and Jsp.?

B.Sreenivasarao on December 13th, 2010 5:24 pm

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.

Satish on December 27th, 2010 1:14 pm

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

Rahul on February 5th, 2011 11:54 am

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

Keep it up…….

Sushit Kumar on February 16th, 2011 6:21 pm

good

ronak on March 18th, 2011 5:18 am

Hello,

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

Regards
Chetan Pagar

Chetan Pagar on May 18th, 2011 8:58 am

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

PAWAN DWIVEDI on June 7th, 2011 10:38 am

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

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

tuturanjan sahoo on June 17th, 2011 10:34 am

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.

tuturanjan sahoo,ABA,Balasore,Odisha on June 17th, 2011 10:40 am

all questions are not truely……..

Anonymous on July 13th, 2011 9:42 am

thanks buddy thats really helpfull 4 me

vickky on August 15th, 2011 1:37 pm

good article
its is a very important interview question in servlets

captainportal on August 27th, 2011 8:37 am

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

Vikas on September 27th, 2011 9:39 am

Thanks for dis also

Nagraj on October 3rd, 2011 1:20 pm

This site is really great and authentic too…..

Sachin on October 10th, 2011 1:39 pm

1361

96846 on October 15th, 2011 5:56 am

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

mahesh on October 17th, 2011 8:46 am

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..

pankaj on October 17th, 2011 7:09 pm

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.

Joe on October 17th, 2011 7:26 pm

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()

Apurv on November 17th, 2011 3:30 pm

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

sridhar on November 21st, 2011 11:00 am

Nice one:-)

danie on November 21st, 2011 11:12 am

bad

laxminarayana on November 28th, 2011 6:29 am

I am not satiafied

chandara on November 29th, 2011 6:34 am

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

nagu on December 2nd, 2011 3:37 am

nice one with good explanation!

neh on December 5th, 2011 7:03 am

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

swopneel on December 5th, 2011 2:49 pm

its nice…….

sunil on December 14th, 2011 10:12 am

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

Kavin on December 28th, 2011 12:53 pm

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

AAR on January 7th, 2012 6:01 am

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

AAR on January 7th, 2012 6:01 am

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

Mallikarjun on January 18th, 2012 2:34 pm

hello
please tell me

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

Anonymous on January 26th, 2012 10:40 pm

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

Anonymous on January 26th, 2012 10:43 pm

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

Anonymous on January 26th, 2012 10:44 pm

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

pranavi on January 28th, 2012 6:39 pm

great work joe..keep it up man

rahul on February 3rd, 2012 11:32 pm

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

Sonu Singh on February 5th, 2012 3:21 pm


Email:

about
I am Joe, author of this blog. I run this with loads of passion. If you are into java, you may find lot of interesting things around ...more about me. Google+
java badge
Home