What role does the DispatcherServlet play in this lifecycle?

DispatcherServlet is the front controller at the center of every Spring MVC request lifecycle. It receives all incoming requests, delegates to the appropriate handler, and coordinates rendering the final response.

Key Points: • It consults a HandlerMapping to determine which Controller (or handler method) should process the incoming request. • After the Controller runs and returns a Model and a logical view name, DispatcherServlet passes that view name to a ViewResolver. • ViewResolver maps the logical name to an actual View implementation, which DispatcherServlet then asks to render using the Model's data. • DispatcherServlet also handles exception resolution, delegating to HandlerExceptionResolver beans (or @ControllerAdvice methods) when a controller throws. • Because it's a servlet, it's registered in web.xml or auto-configured by Spring Boot, and every part of the MVC flow passes through it.

Example: For a request to /orders/42, DispatcherServlet finds the mapped controller method, receives back the Model and view name "orderDetail", resolves that to /WEB-INF/views/orderDetail.jsp, and writes the rendered HTML to the response.

Interview Tip: A concise interview answer is:

"DispatcherServlet is the front controller for every Spring MVC request — it routes the request to the right handler via HandlerMapping, takes the returned Model and view name, and uses ViewResolver to render and send back the final response. It's also the central point where exceptions get routed to exception handlers."