Spring MVC request and response flow explanation
Asked Answered
S

3

9

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.

Syllepsis answered 13/1, 2015 at 9:22 Comment(4)
read section 7.1 here for basics and complete chapter 7 for end to end understanding.Diuretic
javadecodedquestions.blogspot.in/2013/03/…Bigotry
You can find good explanation here https://mcmap.net/q/686789/-how-does-the-dispatcherservlet-resolver-and-controllers-interact-duplicateLansquenet
How Spring MVC Framework works? How HTTP Request is processed?Mulholland
S
17
  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.
Sandasandakan answered 13/1, 2015 at 10:19 Comment(2)
Thank's Harshal Patil.Syllepsis
The first request will be received by DispatcherServlet. The first request?Mulholland
L
1

Spring Flow First Request from JSP/HTML will hit the dispacher servlet, Based on the xml file it will go to particular controller, After going to controller it search for request mapping , based on request mapping it will go to the particular method and follows instructions and takes the model and view and give it to view resolver via dispacher servlet and view resolver will display the view.

Lheureux answered 11/4, 2017 at 10:3 Comment(0)
E
0

I supplement the above explanations. request flow is like below.

Client --> WAS(go through filters) --> DispatcherServlet.doService, doDispatch --> Dispatcher Servlet.handlerMapping,hanlderAdapter --> Controller return ModelAndView --> DispatcherServlet.processDispatchResult, render, resolveViewName --> View --> Client.

I think debugging DispatcherServlet's methods with break points is a good way to understand request flow.

Ejection answered 27/4, 2022 at 8:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.