following a request through Spring MVC

[color=red]以下为自我记录,翻译玩的,如出现错误请参考英文O(∩_∩)O~[/color]

[color=blue]following a request through Spring MVC[/color]

[img]http://dl.iteye.com/upload/attachment/600885/15172c5a-4cd3-3582-a7d7-caa8ad1862f0.png[/img]

As we can see in the picture, When the request leaves the browser, it carries information what user is asking for. At least, the request will be carrying the requested URL. But it may carry additional data such as the information submitted in a form by the user.

当请求离开浏览器的时候,它携带了一些关于用户请求的信息。至少包括用户请求的URL。而且它也可能携带更多的消息,如一些表单提交的信息等。

The first stop in the request’s travels is at Spring’s DispatcherServlet. Like most Java-based web 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 actual processing. In the case of Spring MVC, DispatcherServlet is the front controller.

请求的第一站是到达Spring的DIspatcherServlet。像其他一些java框架一样,Spring mvc框架把请求发送给这个前端控制器。前端控制器是一种常见的web应用模式,一个servlet负责将一个请求发送到其他的组件来进行实际操作。就Spring MVC而言,DispatcherServlet就是这样一个前端控制器。


After you set up a DispatcherServlet, and a request comes in for that specific DispatcherServlet, the DispatcherServlet starts processing the request as follows:

当DispatcherServlet启动以后并且一个请求到达DispatcherServlet,DispatcherServlet会运行下面的步骤:

1. The WebApplicationContext is searched for and bound in the request as an attribute that the controller and other elements in the process can use. It is bound by default under the key DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE.

1. WebApplicationContext会被搜索出来,然后放入request当中,这样WebApplicationContext里面的controller和其他的一些元素就可以在process过程中被使用了。WebApplicationContext在request当中的key是DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE。具体见源码。

2. The locale resolver is bound to the request to enable elements in the process to resolve the locale to use when processing the request (rendering the view, preparing data, and so on). If you do not need locale resolving, you do not need it.

2. 本地的resolver同样也会放入request当中(LOCALE_RESOLVER_ATTRIBUTE),当需要渲染view,准备data的时候会用上。如果你不需要locale resolving, 你可以不使用它。

3. The theme resolver is bound to the request to let elements such as views determine which theme to use. If you do not use themes, you can ignore it.

3. theme resolver同样也放入request当中,让一些元素,如views来决定哪个theme来使用。如果你不需要,可以不用使用。

4. If you specify a multipart file resolver, the request is inspected for multiparts; if multiparts are found,the request is wrapped in a MultipartHttpServletRequest for further processing by other elements in the process. See Section 16.10, “Spring's multipart (file upload) support” for further information about multipart handling.

4. 如果你指定了多文件的resolver,那么request就会检查multiparts;如果multiparts被发现,那么request就会被封装成为一个MultipartHeepServletRequest。

5. An appropriate handler is searched for. If a handler is found, the execution chain associated with the handler (preprocessors, postprocessors, and controllers) is executed in order to prepare a model or rendering.

5. 合适的handler将会被搜索,如果一个合适的handler被发现了,那么它就会被加入到执行链中,以便准备model或者渲染。

6. If a model is returned, the view is rendered. If no model is returned, (may be due to a preprocessor or postprocessor intercepting the request, perhaps for security reasons), no view is rendered, because the request could already have been fulfilled.

6. 如果一个model被返回了,一个视图将被返回。如果没有model返回,(或许是preprocessor或者postprocessor拦截了请求,或许是出于安全的原因)那么没有视图会被渲染,因为请求可已经被完成了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值