Spring / Spring MVC Interview questions
What is DispatcherServlet in Spring MVC Framework?
Spring web MVC framework is request-driven, flows through the central Servlet, DispatcherServlet that handles all the HTTP requests and responses. Spring's DispatcherServlet is completely integrated with the Spring IoC container so it allows you to use every feature that Spring has along with Request handling.
After receiving an HTTP request, DispatcherServlet gets helps from the HandlerMapping (configuration files) to resolve and call the appropriate Controller. The Controller takes the request and calls the appropriate service methods and set model data and then returns view name to the DispatcherServlet. The DispatcherServlet will take help from ViewResolver to resolve the defined view for the request. Once view is finalized, The DispatcherServlet passes the model data to the view which is finally rendered on the browser.
By default, DispatcherServlet resolves its configuration file using <servlet_name>-servlet.xml. For example, with the above web.xml file, DispatcherServlet will look for springMVC-servlet.xml file in classpath.
DispatcherServlet is the front controller in Spring MVC that intercepts every requests and then dispatches/forwards it to an appropriate controller.
More Related questions...