The Servlet API From Zero
Learn the foundation under every Java web framework: what a servlet is, the servlet container and its thread-per-request lifecycle, handling HTTP by hand with HttpServlet, URL mapping and the front-controller pattern, filters and the filter chain, and sessions. Spring's DispatcherServlet, JAX-RS, and middleware all live on top of this — see it bare.
- What a Servlet Is A servlet is a Java object that handles an HTTP request and produces a response — the base unit every Java web framework is built on. Here's the mental model and a first one.
- The Servlet Container & Lifecycle How the container runs a servlet: init/service/destroy, one shared instance serving every request on its own thread, and why that shared instance is exactly why your servlets (and Spring controllers) must be stateless.
- Handling Requests with HttpServlet Override doGet/doPost on HttpServlet, read params, headers, and the raw body from the request, write status, headers, and JSON to the response — the unglamorous truth beneath @GetMapping.
- Mapping & the Front-Controller Pattern How the container decides which servlet handles which URL, why one-servlet-per-URL doesn't scale, and the front-controller pattern — one servlet routing everything — that is exactly what Spring's DispatcherServlet does.
- Filters & the Chain A filter intercepts every request before your servlet and the response after, without the servlet knowing. Chained together, filters are the root of what every framework calls middleware.
- Sessions & State HTTP forgets you between requests, yet apps keep you logged in. Here's the mechanism: a session id in a cookie, server-side state behind it — and the stateless token alternative.
- From Servlets to Frameworks The payoff: see the servlet under every Java web framework. DispatcherServlet, @GetMapping, Spring Security, middleware, and JAX-RS all map back to the lifecycle, front controller, and filter chain you now know.