Backend development refers to the server-side part of web or application development that focuses on databases, server logic, and application programming interfaces (APIs) to ensure data and functionality work correctly behind the scenes. It handles how information is stored, processed, and delivered to the frontend or user interface.

Java Servlets

A Servlet is essentially a Java class that extends the capabilities of a server, typically a web server. It runs inside a Servlet Container (like Apache Tomcat) and is primarily used to handle client requests (most commonly HTTP requests), process data on the server-side, and dynamically generate responses back to the client, forming the backbone for dynamic Java web applications.

Characteristics of a servlet

Java Servlet Architecture

  1. Client Request: The client, typically a web browser, sends a request (e.g., an HTTP GET or POST request) to the web server.
  2. Server to Container Hand-off: The web server receives the request and, recognizing it as a request for a Servlet, forwards it to the Servlet Container (also known as the web container or servlet engine). The container is responsible for managing the lifecycle of the Servlet.
  3. Thread Creation and Invocation: The Servlet Container reads the request's URL, identifies the target Servlet, and calls it. Critically, it creates a new thread for the execution of that Servlet. If multiple requests arrive for the same Servlet concurrently, a new, separate thread is created for each request.
  4. Processing and Response Generation: The Servlet processes the request. This often involves interacting with resources like a database or performing business logic. It then prepares a response object and sends this response object back to the web server.
  5. Response to Client: Finally, the web server takes the response object received from the Servlet Container and sends the resulting response (like an HTML page) back to the client (the web browser). Would you like a brief explanation of the key difference between a Web Server and a Servlet Container?

Screenshot 2025-11-06 at 2.38.37 PM.png

Servlet Lifecycle

The Servlet Lifecycle is governed by the Servlet Container (or web container) and consists of three main stages, represented by three methods defined in the javax.servlet.Servlet interface:

1. Initialization Stage: init() Method