Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC request and response flow explanation

I can't find correct client request flow in below syntax.Could someone please clarify what is happening here?

Client(1) --> Dispatcher Servlet(2) --> Handler Mapping(3) --> Controller(4) -->
ModelAndView(5) --> viewResolver(6) --> View(7) --> Client(1) 

If possible please specify what are the corresponding spring classes/interfaces used in spring MVC process.

like image 622
Balasubramani Avatar asked Jan 13 '15 09:01

Balasubramani


People also ask

What is Spring MVC Can you explain flow from the JSP to database?

Spring MVC framework enables separation of modules namely Model, View, and Control and seamlessly handles the application integration. This enables the developer to create complex applications also using plain java classes. The model object can be passed between view and controller using Maps.

How does Spring MVC handle request?

As seen in earlier section, the web container directs all MVC request to the Spring DispatcherServlet. The Spring Front controller will intercept the request and will find the appropriate handler based on the handler mapping (configured in Spring configuration files or annotation).

What is life cycle of Spring MVC?

There is a Front Controller pattern and the Front Controller in Spring MVC is DispatcherServlet. Upon every incoming request from the user, Spring manages the entire life cycle as described in here. In the overall view, DispatcherServlet dispatches the request to a controller for a service at the back-end.


1 Answers

  1. Request will be received by DispatcherServlet.
  2. DispatcherServlet will take the help of HandlerMapping and get to know the @Controller class name associated with the given request.
  3. So request transfer to the @Controller, and then @Controller will process the request by executing appropriate methods and returns ModelAndView object (contains Model data and View name) back to the DispatcherServlet
  4. Now DispatcherServlet send the model object to the ViewResolver to get the actual view page.
  5. Finally, DispatcherServlet will pass the Model object to the View page to display the result.
like image 67
Harshal Patil Avatar answered Oct 31 '22 15:10

Harshal Patil