Types of Servlet

  • Generic Servlets: These are those servlets that provide functionality for implementing a servlet. It is a generic class from which all the customizable servlets are derived. It is protocol-independent and provides support for HTTP, FTP, and SMTP protocols. The class used is ‘javax.servlet.Servlet’ and it only has 2 methods – init() to initialize & allocate memory to the servlet and destroy() to deallocate the servlet.
  • HTTP Servlets: These are protocol dependent servlets, that provides support for HTTP request and response. It is typically used to create web apps. And has two of the most used methods – doGET() and doPOST() each serving their own purpose.

There are three potential ways in which we can employ to create a servlet:

  • Implementing Servlet Interface
  • Extending Generic Servlet
  • Extending HTTP Servlet

Servlet Architecture

Servlets are grouped under the Advanced Java tree that is used to create dynamic web applications. Servlets are robust, well scalable, and are primarily used in developing server-side applications. If we go a little back in time, we would be able to witness that before the introduction of servlets, CGI (Common Gateway Interface) was used. Among several indigenous tasks that a servlet is capable of doing, dynamically performing client requests and responses are most common. Other tasks that a servlet can do effectively are:

  • Can easily manage/control the application flow.
  • Suitable to implement business logic.
  • Can effectively balance the load on the server side.
  • Easily generate dynamic web content.
  • Handle HTTP Request and Response
  • Also act as an interceptor or filter for a specific group of requests.

Similar Reads

Types of Servlet

Generic Servlets: These are those servlets that provide functionality for implementing a servlet. It is a generic class from which all the customizable servlets are derived. It is protocol-independent and provides support for HTTP, FTP, and SMTP protocols. The class used is ‘javax.servlet.Servlet’ and it only has 2 methods – init() to initialize & allocate memory to the servlet and destroy() to deallocate the servlet. HTTP Servlets: These are protocol dependent servlets, that provides support for HTTP request and response. It is typically used to create web apps. And has two of the most used methods – doGET() and doPOST() each serving their own purpose....

Components of Servlet Architecture

Servlet Architecture contains the business logic to process all the requests made by client. Below is the high-level architecture diagram of servlet. Let’s see in brief, how does each component add to the working of a servlet....