前端控制器接收请求
调用doDispatch方法:
protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
HttpServletRequest processedRequest = request;
HandlerExecutionChain mappedHandler = null;
boolean multipartRequestParsed = false;
。。。。。
}
前端控制器调用HandlerMapping(处理器映射器)根据url查找Handler
在doDispatch方法中:
mappedHandler = this.getHandler(processedRequest);
Handler的实现:
protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
Iterator var2 = this.handlerMappings.iterator();
HandlerExecutionChain handler;
do {
if (!var2.hasNext()) {
return null;
}
HandlerMapping hm = (HandlerMapping)var2.next();
if (this.logger.isTraceEnabled()) {
this.logger.trace("Testing handler map [" + hm + "] in DispatcherServlet with name '" + this.getServletName() + "'");
}
handler = hm.getHandler(request);
} while(handler == null);
return handler;
}
调用处理器适配器执行Handler,得到执行的结果ModelAndView mv
在doDispatch方法中:
mv = ha.handle(processedRequest, response, mappedHandler.getHandler());
视图渲染,将model数据填充到request域
doDispatch->processDispatchResult->render
在render方法中,视图解析得到view:
view = resolveViewName(mv.getViewName(), mv.getModelInternal(), locale, request);
调用view的渲染方法,将model数据填充到request域。在render方法中,调用View接口的render方法。
view.render(mv.getModelInternal(), request, response);