---
description: Describe about servlet in java
---

# What is Servlet in Java ?

Servlets are a component of the JEE framework used for web development. Servlet is a class that handles requests, processes them and reply back with a response. Servlets are under the control of another Java application called a _**Servlet Container.**_ Servlets need to be registered first so that a container, When an application running in a web server receives a reques&#x74;_,_ the Server hands the request to the Servlet Container – which in turn passes it to the target Servlet.

For servlet life cycle including 3 part :

* init()
* service()
* destroy()

**init()**

1. Loads the servlet class
2. Creates an instance of the servlet class
3. Initializes it by calling the _init_ method

**service()**

This method is only called after the servlet's _init()_ method has completed successfull&#x79;_._&#x54;he Container calls the _service()_ method to handle requests coming from the client, interprets the HTTP request type (_GET_, _POST_, _PUT_, _DELETE_, etc.) and calls _doGet_, _doPost_, _doPut_, _doDelete_, etc. methods as appropriate.\
\
**destroy()**

Called by the Servlet Container to take the Servlet out of service.This method is only called once all threads within the servlet's _service_ method have exited or after a timeout period has passed. After the container calls this method, it will not call the _service_ method again on the Servlet.



Reference: [https://www.baeldung.com/intro-to-servlets](https://www.baeldung.com/intro-to-servlets)
