java Spring MVC 请求和响应流程说明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27918643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring MVC request and response flow explanation
提问by Balasubramani
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.
如果可能,请指定在 spring MVC 过程中使用的相应 spring 类/接口是什么。
回答by Harshal Patil
- Request will be received by
DispatcherServlet
. DispatcherServlet
will take the help ofHandlerMapping
and get to know the@Controller
class name associated with the given request.- So request transfer to the
@Controller
, and then@Controller
will process the request by executing appropriate methods and returnsModelAndView
object (contains Model data and View name) back to the DispatcherServlet - Now
DispatcherServlet
send the model object to theViewResolver
to get the actual view page. - Finally,
DispatcherServlet
will pass the Model object to the View page to display the result.
- 请求将由 接收
DispatcherServlet
。 DispatcherServlet
将借助HandlerMapping
并了解@Controller
与给定请求关联的类名。- 所以请求转移到
@Controller
,然后@Controller
将通过执行适当的方法处理请求并将ModelAndView
对象(包含模型数据和视图名称)返回给 DispatcherServlet - 现在
DispatcherServlet
将模型对象发送到ViewResolver
以获取实际视图页面。 - 最后,
DispatcherServlet
将Model对象传递给View页面来显示结果。
回答by Singupurapu prudhvi raj
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.
来自 JSP/HTML 的 Spring Flow First Request 将命中 Dispacher servlet,根据 xml 文件,它将转到特定的控制器,在去控制器后搜索请求映射,根据请求映射,它将转到特定的方法并按照说明执行并获取模型和视图,并通过调度程序 servlet 将其提供给视图解析器,视图解析器将显示该视图。