What is Generic Servlet and how it is different from Http
Servlet?

Answer Posted / qim2010

Both these classes are abstract but the differences are

A GenericServlet has a service() method to handle
requests.
The HttpServlet extends GenericServlet and adds support
for HTTP
protocol based methods like doGet(), doPost(), doHead()
etc. All
client requests are handled through the service() method.
The service method dispatches the request to an appropriate
method like doGet(), doPost() etc to handle that request.
HttpServlet also has methods like doHead(), doPut(),
doOptions(),
doDelete(), and doTrace().


GenericServlet is Protocol independent. GenericServlet is
for servlets
that might not use HTTP (for example FTP service).
But HttpServlet is protocol dependent (i.e. HTTP).

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the new features added to servlet 2.5?

824


How do we translate jsp?

770


Write a simple servlet program to print the contents of html.

776


Difference between get and post in java servlets?

754


How to upload a file to the server using servlet?

728


What is a servlet context?

818


Why the concept of single thread model interface is used?

725


What if you need to span your transaction across multiple servlet invocations?

800


Define servlet mapping?

899


What are the differences between servlet context vs servlet config?

811


Why is servlet used?

892


How forward () method is different from send redirect () method?

708


What is the need of servlet filters?

734


What is ServletContext object?

836


What is servlet in tomcat?

773