liveBook · Manning

DispatcherServlet

As explained in Spring Start Here, Second Edition

A dispatcher servlet is the Spring MVC servlet that receives web requests and coordinates their dispatch to controller actions and response rendering.

The DispatcherServlet is Spring MVC’s entry point for HTTP requests, also called a front controller. Tomcat sends requests to it, and it coordinates dispatch to a controller action and the response back to the client. section 7.3

A typical request moves through these steps:

  • The servlet asks handler mapping to find the controller action associated with the request, such as one marked with @RequestMapping. section 7.3
  • It calls the mapped action. If no action matches, the app responds with HTTP 404 Not Found. section 7.3
  • For a web page, the action returns a view name and the servlet obtains the view content for the response. section 7.3

Page request and REST response

A controller action mapped to `/home` can return `home.html` for the DispatcherServlet to render. A REST endpoint uses the same MVC mechanism, but the servlet returns the action’s data directly instead of looking for a view. section 7.3 section 10.1

Figure 7.18 The Spring MVC architecture. In the diagram, you find the main components of Spring MVC. These components and the way they collaborate are responsible for a web app’s behavior. The controller (shaded differently) is the only component you implement. Spring Boot configures the other components.

The architecture diagram shows the collaborating Spring MVC components and distinguishes the controller developers implement from components Spring Boot configures. section 7.3

How Spring Start Here, Second Edition covers it

How deep it goes
Traces Tomcat-to-servlet dispatch through handler mapping and controller execution, then contrasts view rendering with direct REST responses.
Examples
Uses a `/home` mapping returning `home.html` and contrasts REST actions that return response data directly.
What you can do after
Understand how requests reach controller actions and why REST responses bypass view resolution.
How it connects
Connects Tomcat, handler mapping, controller actions, view resolution, and REST response handling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.