Monday, February 8, 2010

Spring MVC framework



From the time that a request is received by Spring until the time that a response is returned to the client, many pieces of the Spring MVC framework are involved. The process starts when a client (typically a web browser) sends a request (1) .The first component to receive the request is Spring’s DispatcherServlet. Like most Java-based MVC frameworks, Spring MVC funnels requests through a single front controller servlet. A front controller is a common web-application pattern where a single servlet delegates responsibility for a request to other components of an application to perform the actual processing. In the case of Spring MVC, DispatcherServlet is the front controller.
The Spring MVC component that is responsible for handling the request is a Controller. To figure out which controller should handle the request, DispatcherServlet starts by querying one or more HandlerMappings (2). A HandlerMapping typically performs its job by mapping URL patterns to Controller objects.
Once the DispatcherServlet has a Controller object, it dispatches the request to the Controller to perform whatever business logic it was designed to do (3) (Actually, a well-designed Controller performs little or no business logic itself and instead delegates responsibility for the business logic to one or more service objects.) Upon completion of business logic, the Controller returns a ModelAndView object (4) to the DispatcherServlet.
The ModelAndView can either contain a View object or a logical name of a View object. If the ModelAndView object contains the logical name of a View, the Dispatcher- Servlet queries a ViewResolver (5) to look up the View object that will render the response. Finally, the DispatcherServlet dispatches the request to the View object (6) indicated by the ModelAndView object. The View object is responsible for rendering a response back to the client.

No comments:

Post a Comment