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
- 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
the method that u have defined for servlet mapping is not correct. i am not satisfied with it.
aam voi saav tamne kai bhaan pade che ke nai su magaj nu dahi karo cho
Your site is vary good.i am get more knowledge of your exa. Gernic and http servlet.
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..,
Your site is superb ..complete knowledge provider.
What is the Basic difference between Servlet and Jsp.?
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.
your faculty having less knowleadge about servlet and provides the basic knowleadge.
Hey, this site is good.
I m gaining more about java from this site.
Keep it up…….
good
Hello,
It’s good content on your site… Specially I like the arrangement of content and website look..
Regards
Chetan Pagar
thanks this is really a good effort i’m satisfied with your answer
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 .
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
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.
all questions are not truely……..
thanks buddy thats really helpfull 4 me
good article
its is a very important interview question in servlets
Thanx dear…..
Its a very impotant interview question and its very easy to set in my mind this topics……
Thanks for dis also
This site is really great and authentic too…..
this is helping me a lot thank you for keeping all these
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,
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.
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()
Nice one:-)
Its really fantastic ….now i got a clear idea about the Genric and HttpServlet …thanks for your explanation…..:
bad
I am not satiafied
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
nice one with good explanation!
what is the use of Generic servlet class even though we have servlet interface
its nice…….
That Cool…But needs some examples to explain that will be Good….
How To achive(I know session cant be used in Generic ) session in Generic servlet by using ftp protocal
How To achive(I know session cant be used in Generic ) session in Generic servlet by using ftp protocal
when GenericServlet implements Serializable, then what is the need to re-implement it in HttpServlet class?
hello
please tell me
when we send the request to server for servlet then is it http request or https request..?
please tell me the complete flow of http and htts ….
please tell me the complete flow of http and htts ….and etc
ya this site is really good this site containing very useful information
great work joe..keep it up man
Your site is very good, it describe real language of servlet.
So as per previous discussion,we can write a program with out having service() method,with using HTTP.can anyone explain clearly please
Thanks, Through this informations,
students taking these informations &
it is easy to write the Diff. bet.
HttpSevlet & GenericServlet
Thanks.
thank foe information that u had given in this blog….
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
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
i got lots of information…really very good site.
good for knowledge……
thnq bro..
why HttpServlet is declared as abstract?
There is no abstract methods in httpservlet then y it is abstract?
please upload that httpservlet class definition
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
why http servlet handle only http protocals?
why genaric servlet handle any type of protocals?
but differentiated of inheritances concept why?
give some more pointss
hii guys,
why all user defined servlet classes extends HttpServlet? if anyone knows kindly reply?
thanks this type of information. we can know that diff. between generic servlet and http servlet…
difference between protocol independent and protocol dependent
i am satisfied with your comment.
thank you.
sir,
really it is very easy to understand thankyou sir…
is genericServlet suppport http protocol
Yes GenericServlet does support HTTP protocol.
HttpServlet is protocol specific.
this is the correct answer…
what is given in above article is correct.what you have posted is wrong
awsome your site is suprb matter also gd..
—> 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.
Servlet is basically a java code which can include html where as jsp is combination of java code and html.
ya u r given good explanation man.
thanks joe good one
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
ok
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().
Q. 1. – Can Generic servlet handle HTTP request also ?
Q 2 . – Is Generic Servlet stateful if getting the non HTTP request ?
difference between inner class and outer class
u r right saying bro
I am agree with u
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 :)
Yes genericservlet can handle the http protol because it is protocl independent
It can also handle smtp, ftp protol also