1.前端控制器接收請求,調用doDispatch
方法前端
protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpServletRequest processedRequest = request; HandlerExecutionChain mappedHandler = null; boolean multipartRequestParsed = false; ... }
2.前端控制器調用HandlerMapping
(處理器映射器)根據url查找Handlerjava
mappedHandler = getHandler(processedRequest);
protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { 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) { return handler; } } return null; }
3.調用處理器適配器執行Handler,獲得執行的結果ModelAndView mv
。在doDispatch
方法中app
mv = ha.handle(processedRequest, response, mappedHandler.getHandler());
4.視圖渲染。doDispatch
->processDispatchResult
->render
。在render
方法中,視圖解析獲得view。this
view = resolveViewName(mv.getViewName(), mv.getModelInternal(), locale, request);
調用view的渲染方法,將model數據填充到request域。在render
方法中,調用View
接口的render
方法url
view.render(mv.getModelInternal(), request, response);