jump to navigation

Types of Servlets January 23, 2007

Posted by Allu in Servlets.

Servlets must implement the interface javax.servlet.Servlet. There are two main types of servlets:

  • Generic servlets extend javax.servlet.GenericServlet. Generic servlets are protocol independent, meaning that they contain no inherent support for HTTP or any other transport protocol. 
  • HTTP servlets extend javax.servlet.HttpServlet. These servlets have built-in support for the HTTP protocol and are much more useful in an Browser environment

Servlets that extend HttpServlet are much more useful in an HTTP environment, since that is what they were designed for. We recommend that all  Servlets extend from HttpServlet rather than from GenericServlet in order to take advantage of this built-in HTTP support.

For both types of Servlets, you can implement the constructor method init() and/or the destructor method destroy() if you need to initialize or deallocate resources. 

All Servlets must implement a service() method. This method is responsible for handling requests made to the Servlet. For generic Servlets, you simply override the service() method to provide routines for handling requests. HTTP Servlets provide a service method that automatically routes the request to another method in the servlet based on which HTTP transfer method is used, so for HTTP Servlets you would override doPost() to process POST requests, doGet() to process GET requests, and so on.



1. ashish - March 7, 2009

thanks a lot i was looking for this particular servelets

2. ashish - March 7, 2009

thanks a lot i was looking for this particular serveets

3. Smita - February 17, 2010

Thanks for such type of information with details.

4. Chintan - April 10, 2010

thanks !!!

5. Allu - June 28, 2011

This is exactly right

6. Rajasekhar - July 14, 2011

Saying there are two types of servlets is wrong (Genericservlets and HttpServlets)… there are ‘n’ number of servlets based on our requirement like smtp servlets, httpservlet, ftpservlets etc…..

7. MAHESH KRISHNA - October 5, 2011

ya its nice

8. balakrishna nandamuri - August 14, 2012

good explanation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: