🔍 What I Wish I Learned About Servlets and JSP Before Diving Into Spring Framework

Table of contents
- đź§ What Spring Is Really Doing Behind the Scenes
- đź§± So What Is a Servlet, Exactly?
- 🔄 Servlet Lifecycle: Why You Should Know It
- 🚦 DispatcherServlet: Spring’s Heartbeat
- đź§ľ Do I Need to Learn JSP?
- đź§ Putting It All Together: Spring MVC Flow with Servlet Context
- âś… Checklist: What Servlet/JSP Knowledge You Actually Need Before Spring
- In a nutshell 🥜

When I began learning the Spring Framework, especially Spring MVC, I thought I could skip the older technologies like Servlets and JSP, assuming Spring was modern and there was no need to spend time on legacy Java web tech. That mindset caused me problems because Spring was built on top of Servlets and JSP, and understanding those basics would have made learning Spring much easier. If you're just starting with Spring like I did, this article covers everything I wish someone had explained to me before I got overwhelmed by annotations and auto-config magic.
đź§ What Spring Is Really Doing Behind the Scenes
You write this in Spring:
@RestController
public class HelloController {
@GetMapping("/hello")
public String sayHello() {
return "Hello, world!";
}
}
Simple, right? But what you’re not seeing is what’s happening under the hood:
Spring sets up a
DispatcherServlet
(which is just a fancyHttpServlet
)It routes your
/hello
request toHelloController
It handles the HTTP request, builds the response, and returns it
That whole process is built on the Servlet API.
So even if you never touch a raw HttpServlet
, your Spring app is full of them — just abstracted.
đź§± So What Is a Servlet, Exactly?
A Servlet is a Java class that runs inside a servlet container (like Tomcat) and responds to HTTP requests.
Here’s what a simple one looks like:
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.getWriter().write("Hello from Servlet!");
}
}
This is the low-level version of what Spring’s @RestController
is doing for you.
Once I understood that, suddenly:
@RequestMapping
made senseHttpServletRequest
andHttpServletResponse
weren’t scaryThe whole Spring MVC flow felt less “magical”
🔄 Servlet Lifecycle: Why You Should Know It
Here’s how Servlets live and die:
init()
→ Called once when the servlet is loadeddoGet()
/doPost()
→ Called for each incoming requestdestroy()
→ Called before the servlet is taken down
Knowing this helped me understand:
When Spring beans are created and destroyed
How
@PostConstruct
and@PreDestroy
relate to servlet lifecycleWhy stateless components are safer for multi-threaded web apps
🚦 DispatcherServlet: Spring’s Heartbeat
Spring MVC is built around one central servlet: DispatcherServlet
.
Here’s what it does:
Intercepts all HTTP requests (
/api
,/home
, etc.)Decides which controller should handle the request
Passes the request to the right controller method
Returns the response (JSON, HTML, etc.)
It’s literally configured as a Servlet in Spring Boot’s auto-configuration.
Understanding this servlet-based routing system helped me troubleshoot:
Why some URLs weren’t being matched
How Spring MVC processes
@RequestParam
,@PathVariable
, etc.How exception handling works in the request pipeline
đź§ľ Do I Need to Learn JSP?
Short answer: No — unless:
You’re maintaining a legacy Java EE app
You’re specifically working with JSP views (not common in new Spring Boot apps)
But I still recommend learning basic JSP syntax, because:
Many older Spring tutorials still use JSP
You’ll understand how the view layer evolved
You’ll appreciate why modern Spring uses Thymeleaf instead
Quick JSP Overview:
<%@ page contentType="text/html" %>
<html>
<body>
<h1>Hello, <%= request.getParameter("name") %></h1>
</body>
</html>
JSP lets you embed Java into HTML — not ideal for clean code, which is why modern apps use template engines like Thymeleaf or full frontend frameworks (React, Angular, etc.).
đź§ Putting It All Together: Spring MVC Flow with Servlet Context
Here’s how a Spring MVC request is handled:
User sends a request:
GET /user/10
Tomcat receives it and passes it to Spring’s DispatcherServlet
DispatcherServlet consults HandlerMapping to find the right controller
Spring calls your method:
@GetMapping("/user/{id}")
The method returns data (JSON, HTML, etc.)
DispatcherServlet sends the response back to the browser
If you know how Servlets process requests, this whole flow is super intuitive.
âś… Checklist: What Servlet/JSP Knowledge You Actually Need Before Spring
Concept | Required? | Why It’s Useful |
What is HTTP (GET, POST, headers) | âś… Yes | Core web concepts |
What is a Servlet? | âś… Yes | Spring runs on top of them |
Servlet lifecycle (init , doGet ) | âś… Yes | Matches Spring bean and request handling |
JSP basics (<%= ... %> ) | 🔄 Optional | For legacy understanding |
DispatcherServlet | âś… Yes | Central to Spring MVC |
HttpServletRequest / Response | âś… Yes | You'll still use these in Spring sometimes |
web.xml deployment descriptor | ❌ No | Spring Boot auto-configures everything |
In a nutshell 🥜
If you're starting with Spring or Spring MVC, here's how much Servlet and JSP knowledge you actually need:
✅ Understand what a Servlet is — a Java class that handles HTTP requests.
✅ Know the Servlet lifecycle —
init()
,doGet()
,doPost()
,destroy()
.✅ Get what DispatcherServlet does — it's the front controller in Spring MVC.
âś… Recognize
HttpServletRequest
andHttpServletResponse
— Spring still uses them under the hood.🔄 JSP is optional — good to know for legacy projects or understanding older tutorials, but most modern Spring apps use Thymeleaf or APIs instead.
❌ You don’t need to touch
web.xml
or build a full JSP/Servlet app — Spring Boot automates that away.
Spending just a few hours on Servlet basics will massively reduce confusion when you jump into Spring — I wish I did it earlier.
Subscribe to my newsletter
Read articles from Arkadipta Kundu directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Arkadipta Kundu
Arkadipta Kundu
I’m a Computer Science undergrad from India with a passion for coding and building things that make an impact. Skilled in Java, Data Structures and Algorithms (DSA), and web development, I love diving into problem-solving challenges and constantly learning. Right now, I’m focused on sharpening my DSA skills and expanding my expertise in Java development.