Spring Framework FAQ: Top Questions
21. What is the DispatcherServlet in Spring MVC?
DispatcherServlet
is the front controller in Spring MVC that handles all incoming HTTP requests and delegates them to appropriate handlers.
📘 Core Responsibilities:
- Intercept requests using URL mapping.
- Delegate to controllers, resolve views, handle exceptions.
📥 Example (web.xml-style config):
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
🏆 Expected Output:
Requests routed through DispatcherServlet to respective controller methods.
🛠️ Use Cases:
- Routing all web requests in Spring MVC apps.
- Centralizing request processing and view resolution.