SPRINGMVC Study Notes (4)-Front Controller
- SPRINGMVC Learning Note 4-Front Controller
In this paper, through the Front Controller source code Analysis SPRINGMVC execution Process
1. Front Controller receives request
Calling doDispatch methods
protectedvoiddoDispatchthrows Exception { HttpServletRequest processedRequest = request; null; booleanfalse; 。。。。。}
2. Front-end controller call HandlerMapping (processor mapper) find handler based on URL
// Determine handler for the current request.mappedHandler = getHandler(processedRequest);
/** * Return The Handlerexecutionchain for this request. * <p>tries All handler mappings in order. * @param Request current HTTP request * @return The Handlerexecutionchain, or {@code null} if no Han Dler could be found * / protectedHandlerexecutionchainGetHandler(HttpServletRequest request)throwsException { for(Handlermapping HM: This. handlermappings) {if(Logger.istraceenabled ()) {Logger.trace ("Testing handler map ["+ HM +"] in Dispatcherservlet with Name '"+ getservletname () +"'"); } Handlerexecutionchain handler = Hm.gethandler (request);if(Handler! =NULL) {returnHandler } }return NULL; }
3. Call the processor adapter to execute the handler and get the result of executionModelAndView mv
In the doDispatch method
// Actually invoke the handler.mv = ha.handle(processedRequest, response, mappedHandler.getHandler());
4. View rendering, populating the model data into the request domain
doDispatch, processDispatchResultrender
In the render method, the view is parsed to get view
// We need to resolve the view name.view = resolveViewName(mv.getViewName(), mv.getModelInternal(), locale, request);
Call the Render method of view to populate the request domain with the model data
In a render method, the View method that invokes the interface render
view.render(mv.getModelInternal(), request, response);
Program I also did not read, feeling analysis is relatively shallow, a lot of still did not understand, and so I system read the source code will tidy up a better.
Author @brianway More articles: personal website | CSDN | Oschina
SPRINGMVC Study Notes (4)-Front Controller