Junior — Middle
How does DispatcherServlet determine the target handler for an incoming HTTP request?
sobes.tech AI
Answer from AI
DispatcherServlet in Spring MVC uses a URL request mapping mechanism with handlers (controllers) through HandlerMapping. When an HTTP request is received, DispatcherServlet consults registered HandlerMappings, which analyze the URL and other request parameters to find a suitable handler. This is usually done via @RequestMapping annotations or similar, where the path and HTTP method are specified.
Example: if a controller has a method annotated with @RequestMapping("/users"), then a request to /users will be directed to this method. DispatcherServlet sequentially queries all HandlerMappings until it finds a suitable handler and then delegates control to it.