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 pmthe method that u have defined for servlet mapping is not correct. i am not satisfied with it.
robin on July 13th, 2010 12:04 amaam voi saav tamne kai bhaan pade che ke nai su magaj nu dahi karo cho
Anonymous on August 18th, 2010 10:09 amyou 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 amYour site is vary good.i am get more knowledge of your exa. Gernic and http servlet.
Pawan on October 31st, 2010 3:47 amWhen 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 pmYour site is superb ..complete knowledge provider.
Sheetal on November 27th, 2010 3:40 amWhat is the Basic difference between Servlet and Jsp.?
B.Sreenivasarao on December 13th, 2010 5:24 pmAgain 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 pmyour faculty having less knowleadge about servlet and provides the basic knowleadge.
Rahul on February 5th, 2011 11:54 amHey, this site is good.
I m gaining more about java from this site.
Keep it up…….
Sushit Kumar on February 16th, 2011 6:21 pmgood
ronak on March 18th, 2011 5:18 amHello,
It’s good content on your site… Specially I like the arrangement of content and website look..
Regards
Chetan Pagar on May 18th, 2011 8:58 amChetan Pagar
thanks this is really a good effort i’m satisfied with your answer
PAWAN DWIVEDI on June 7th, 2011 10:38 amGeneric 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
sv on June 15th, 2011 7:00 amdeploy the servlet .
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 amWhat is the difference between GenericServlet and HttpServlet?
tuturanjan sahoo,ABA,Balasore,Odisha on June 17th, 2011 10:40 amGenericServlet 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.
all questions are not truely……..
Anonymous on July 13th, 2011 9:42 amthanks buddy thats really helpfull 4 me
vickky on August 15th, 2011 1:37 pmgood article
captainportal on August 27th, 2011 8:37 amits is a very important interview question in servlets
Thanx dear…..
Vikas on September 27th, 2011 9:39 amIts a very impotant interview question and its very easy to set in my mind this topics……
Thanks for dis also
Nagraj on October 3rd, 2011 1:20 pmThis site is really great and authentic too…..
Sachin on October 10th, 2011 1:39 pm1361
96846 on October 15th, 2011 5:56 amthis is helping me a lot thank you for keeping all these
mahesh on October 17th, 2011 8:46 amyour 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 pmPankaj,
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 pmGenericServlet 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
Apurv on November 17th, 2011 3:30 pmThis 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()
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 amNice one:-)
danie on November 21st, 2011 11:12 ambad
laxminarayana on November 28th, 2011 6:29 amI am not satiafied
chandara on November 29th, 2011 6:34 am1(a).this generic servlet class implements from servlet and servletconfig interfaces
nagu on December 2nd, 2011 3:37 am1(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
nice one with good explanation!
neh on December 5th, 2011 7:03 amwhat is the use of Generic servlet class even though we have servlet interface
swopneel on December 5th, 2011 2:49 pmits nice…….
sunil on December 14th, 2011 10:12 amThat Cool…But needs some examples to explain that will be Good….
Kavin on December 28th, 2011 12:53 pmHow 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 amHow 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 amwhen GenericServlet implements Serializable, then what is the need to re-implement it in HttpServlet class?
Mallikarjun on January 18th, 2012 2:34 pmhello
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 pmplease tell me the complete flow of http and htts ….
Anonymous on January 26th, 2012 10:43 pmplease tell me the complete flow of http and htts ….and etc
Anonymous on January 26th, 2012 10:44 pmya this site is really good this site containing very useful information
pranavi on January 28th, 2012 6:39 pmgreat work joe..keep it up man
rahul on February 3rd, 2012 11:32 pmYour site is very good, it describe real language of servlet.
Sonu Singh on February 5th, 2012 3:21 pm