Servlet and Servlet Container

Servlet and Servlet container together provide the base for building web-based applications.

  • Servlet is a Java class that handles client requests, processes them, and returns a response.
  • Servlet containers (also known as a web container) is a part of a web server that interacts with servlets, manages their lifecycle, and handles communication between the servlet and the client.

Example: Imagine a simple login form on a website. When a user submits their username and password, a servlet handles the request:

In modern Spring Boot applications:

  • We don't write servlets manually as often.
  • Spring Boot handles configuration automatically (auto-configuration).
  • It uses embedded servers like Tomcat or Jetty, so there's no need for an external server setup.

This makes web application development faster and simpler.

  • Removes the need for web.xml configuration.

Why Remove web.xml ?

Earlier Java web apps needed a web.xml file to define servlet mappings and settings. Over time, maintaining it became complex.

Now:

  • Spring Boot uses Java-based configuration and annotations.
  • This approach is cleaner, easier to understand, and reduces the chances of errors.

Example: Spring Boot Controller instead of servlet.

To view or add a comment, sign in

More articles by Deepak Singh

  • Java Reflection

    What is Reflection? Reflection is Java's ability to look into and change classes, methods, fields, and constructors at…

    1 Comment
  • What is Lombok and why we need Lombok?

    🔹 What is Lombok and Why Do We Use It? Lombok is a powerful Java library and designed to reduce boilerplate code in…

  • GraphQL vs REST API — Explained with Real-Life Examples

    Fixed Response vs Flexible Response REST: Has a fixed response. GraphQL: Gives flexibility to consumers — they can…

  • Understanding Kubernetes Architecture: A Breakdown of Clusters, Nodes, Pods, and Containers

    Kubernetes is a powerful orchestration tool for managing containerized applications. To grasp its functionality, it's…

    1 Comment
  • What is GraphQL ?

    🧠 What is GraphQL? GraphQL is not just an API architectural style — It’s a powerful, flexible query language for APIs,…

    1 Comment
  • What is API ?

    🔌 Introduction to APIs An API (Application Programming Interface) is a set of rules that allows different software…

    6 Comments
  • Transaction Management

    💡 What is a Transaction? Transactions are the backbone of any enterprise application. A transaction means a set of…

  • Understanding Java Records

    Introduction: In Java, records are a special type of class designed to minimize boilerplate code when creating data…

  • Sealed Class and Interface

    Sealed classes and interfaces control which other classes or interfaces can extend or implement them. This means you…

  • Key dependencies of Spring Boot

    spring-boot-starter-parent:Provides default configurations and dependency management. Use: In Maven, you include it as…

    2 Comments

Explore content categories