Spring MVC processing and Spring MVC Processing

Source: Internet
Author: User

Spring MVC processing and Spring MVC Processing

1. First, the user sends a request,DispatcherServletWill intercept the request,DispatcherServletAfter receiving the request, do not process it, But parse the URL to obtain the correspondingURI(Resource identifier ).

2.DispatcherServletCallHandlerMapping,HandlerMappingThe role is to resolveRequest Link(URI), And thenRequest Link, Find the appropriate ProcessorHandler(SaidHandler, That isControllerOrAction),HandlerMappingHowever, it is not a simple return processor. Instead, it encapsulates the processor and interceptor to form a processor execution chain (HandlerExecuteChain) ReturnDispatcherServlet.
3.DispatcherServletBased on the obtainedHandlerType, select a suitableHandlerAdapter.

4. InHandlerAdapterCall before executionHandlerInterceptorThe preHander () method.

5.HandlerAdapterDefines how to process the request policy, through the requestURI, RequestMethodAnd ProcessorRequestMappingDefinition, final callHandler(Controller) To process the request and complete the function.

6.ControllerDirectionDispatcherServletReturnsModelAndViewObject (including model data, logical view name)

7. Based on the returned ModelAndView, Select a suitable ViewResolver(It must have been registered in the Spring container. ViewResolver) Return DispatcherServlet. 8. DispatcherServletAccording ModelAndViewModel data in the instance. The logical view name returns the information ViewResolver.
9.   ViewResolverProcess the view and return it to the client. For xml configuration. in the xml configuration file, remember to register HandlerMapping, HandlerAdapter, and ViewResolver. If not, Spring will use the default registration. add the Controller class to facilitate dependency injection. If it is an annotation configuration, you need to add the class in Spring. add in xml
<Context: annotation-config/> <! -- Simplified configuration and combination of @ Resource, @ PostConstruct, @ PreDestroy, and other annotations --> <context: component-scan/> <! -- Automatically scan the package path --> <mvc: annotation-drivent/> <! -- It automatically registers the bean ultannotationhandermappint and AnnotationHanderAdapter beans. However, the disadvantage is that the interceptors attribute cannot be injected and the interceptor cannot be specified. -->

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.