`

following a request through Spring MVC

 
阅读更多
以下为自我记录,翻译玩的,如出现错误请参考英文O(∩_∩)O~

following a request through Spring MVC



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拦截了请求,或许是出于安全的原因)那么没有视图会被渲染,因为请求可已经被完成了。
  • 大小: 22.6 KB
分享到:
评论

相关推荐

    Spring Recipes: A Problem-Solution Approach, Second Edition

    This book provides elementary to advanced code recipes to account for the following, found in the new Spring 3: * Spring fundamentals: Spring IoC container, Spring AOP/ AspectJ, and more * Spring ...

    Getting started with Spring Framework: covers Spring 5(epub)

    Getting started with Spring Framework (4th Edition) is a hands-on guide to begin developing applications using Spring Framework 5. The examples (consisting of 88 sample projects) that accompany this ...

    Manning.Spring.in.Action.4th.Edition.2014.11.epub

    5.1.1. Following the life of a request 5.1.2. Setting up Spring MVC 5.1.3. Introducing the Spittr application 5.2. Writing a simple controller 5.2.1. Testing the controller 5.2.2. Defining class-level...

    Getting.started.with.Spring.Framework.2nd.Edition1491011912.epub

    Getting started with Spring ...Chapter 13 – More Spring Web MVC – internationalization, file upload and asynchronous request processing Chapter 14 – Securing applications using Spring Security

    Apress.Introducing.Spring.Framework.A.Primer.

    After reading this book, you will know how to do the following: • Use the Spring Framework efficiently. • Add persistence through JDBC and NoSQL databases. • Do unit and integration testing. • ...

    Learning Spring Application Development

    you will learn best practices through real-world projects and follow a simple, practical approach to developing high performance and enterprise-grade Java applications with Spring. Starting with the...

    Building Microservices with Spring.epub

    Build web applications using traditional Spring MVC patterns Utilize the reactive programming pattern to build reactive web apps Learn concurrency and handle multiple connections inside a web server...

    Beginning Spring Boot 2 Applications and Microservices with the Spring Framework

    Spring Boot is an opinionated framework following the “Convention Over Configuration” approach, which helps build Spring-based applications quickly and easily. The main goal of Spring Boot is to ...

    asp.net mvc

    Note Because Visual Studio 2008 and Visual Studio 2010 Beta 2 share a component of ASP.NET MVC 2, installing the ASP.NET MVC 2 Release Candidate release on a computer where Visual Studio 2010 ...

    Learning Spring Application Development(PACKT,2015)

    you will learn best practices through real-world projects and follow a simple, practical approach to developing high performance and enterprise-grade Java applications with Spring. Starting with the...

    SpringSource CoreSpring认证考试题库.docx

    题目:Consider the following code sample which creates an ApplicationContext from a file called "application-config.xml" in the "rewards.internal" package, and a file called test-infra-config.xml in ...

    spring-agent.jar

    For environments where class instrumentation is ...Note that the virtual machine has to be started with the Spring agent, by supplying the following JVM options: -javaagent:/path/to/spring-agent.jar

    Beginning-Spring-Boot-2.pdf

    Spring Boot is an opinionated framework following the “Convention Over Configuration” approach, which helps build Spring-based applications quickly and easily. The main goal of Spring Boot is to ...

    product-catalog-spring-mvc-demo:使用Spring MVC和Mongo DB的产品目录演示项目

    01-A)产品列表页 01-B)产品详细信息页面 01-C)产品详细信息页面确认模式 01-D)购物车页面 01-E)搜索功能 01-F)按选定类别列出产品 02项目启动 Following maven archetype is used to create web application `...

    .NET mvc5 code first 教程

    A Visual Studio 2013 project which shows how to use the Entity Framework 6 in an ASP.NET MVC 5 web application project, using the Code First development approach. The previous version that uses EF 5 ...

    thymeleaf-extras-springsecurity-3.0-master.zip

    In order to use the thymeleaf-extras-springsecurity3 or thymeleaf-extras-springsecurity4 modules in our Spring MVC application, we will first need to configure our application in the usual way for ...

    Improving the load-following capability of a solid oxide fuel cell system

    As a new energy technology with distributed generation prospects, the load-following capability of solid oxide fuel cell (SOFC) systems is one of the main obstacles for commercial operation. This ...

Global site tag (gtag.js) - Google Analytics