DispatcherServlet类的相关方法

DispatcherServlet类的相关方法

protected void OnRefresh(ApplicationContext context) 初始化上下文对象后,会回调该方法,完成Spring MVC中默认实现类的初始化

protected void initStrategies(ApplicationContext context) 对MVC的其他部分进行了初始化,例如初始化了处理器映射器、处理器适配器、多媒体解析器、位置解析器、主题解析器、异常解析器、请求到视图名解析器、视图解析器及FlashMapManager

private void initMultipartResolver(ApplicationContext context)初始化多媒体解析器,在initStrategies方法中被调用

private void initLocaleResolver(Application Context context)初始化位置解析器,在initStrategies方法中被调用

private void initThemeResolver(ApplicationContext context) 初始化主题解析器,在initStrategies方法中被调用

private void initHandlerMappings(ApplicationContext context)初始化处理器映射器(可配置多个),在initStrategies方法中被调用

private void initHandlerAdapters(ApplicationContext context)初始化处理器适配器(可配置多个),在initStrategies方法中被调用

private void initHandlerExceptionResolvers(ApplicationContext context)初始化异常解析器(看名字也可以配置多个),在initStrategies方法中被调用

private void initRequestToViewNameTranslator(ApplicationContext context)初始化请求到视图名解析器,在initStrategies方法中被调用

private void initViewResolvers(ApplicationContext context)初始化视图解析器(可配置多个),在initStrategies方法中被调用

private void initFlashMapManager(ApplicationContext context)初始化Flash映射管理器,在initStrategies方法中被调用

public final ThemeSource getThemeSource()获取主题资源

public final MultipartResolver getMultipartResolver()获取多媒体解析器

protcted T getDefaultStrategy(ApplicationContext context, Class strategyInterface)获取默认的策略配置

protected List getDefaultStrategies(ApplicationContext context, Class strategyInterface) 获取默认的策略配置List集合

protected Object createDefaultStrategy(ApplicationContext context, Class<?> clazz)通过上下文对象和相关对象的class类型,创建默认的策略配置

@Override
protected void doService(HttpServletRequest request, HttpServletResponse response)处理request请求,无论通过post方式还是get方式提交的request,最终都会交由doService()处理

protected void doDispatch(HttpServletRequest request, HttpServletResponse response)处理拦截,转发请求,调用处理器获得结果,并绘制结果视图。在doService方法中调用

private void applyDefaultViewName(HttpServletRequest request, ModelAndView mv)设置默认视图名称。在ModelAndView没有配置视图的情况下,会跳转到默认视图

private void processDispatchResult(HttpServletRequest request, HttpServletResponse response, HandlerExecutionChain mappedHandler, ModelAndView mv, Exception e)处理分派结果,响应用户

@Override
protected LocaleContext buildLocaleContext(final HttpServletRequest request)创建本地上下文对象

protected HttpServeltRequest checkMultipart(HttpServletRequest request)throws MultipartException 判断当前请求是否是一个multipart request(即对媒体信息请求)

protected void cleanupMultipart(HttpServletRequest request)清楚多媒体请求信息。在doDispatch方法中调用

protected HandlerExecutionChain getHandler(HttpServletRequest request)throws Exception 获取具体要执行的Handler处理器的方法

protected void noHandlerFound(HttpServletRequest request, HttpServletResponse response)throws Exception 处理在没有匹配到正确的Handler时的逻辑

protected HandlerAdapter getHandlerAdapter(Object handler) throws ServletException 获取处理适配器对象

protected ModelAndView processHandlerException(HttpServletRequest request,HttpServletResponse response, Object handler, Exception e) throws Exception 处理Handler处理器中抛出的异常信息

protected void render(ModelAndView mv, HttpServeltRequest request,HttpServletResponse reponse)throws Exception 完成视图的渲染工作

protected String getDefaultViewName(HttpServletRequest request)throws Exception 获取默认视图名称。在applyDefaultViewName方法中调用

protected View resolveViewName(String viewName, Map< String, Object> model,Locale locale)throws Exception 将ModelAndView中的view定义为view name,进而解析为view实例。在render方法中调用

private void triggerAfterCompletion(HttpServletRequest request,HttpServletResponse response,HandlerExecutionChain mappedHandler,Exception e)throws Exception 从当前的拦截器开始逆向调用每个拦截器的afterCompletion方法,并且捕获它的异常。在调用Handler之前会调用其他配置的每一个HandlerInterceptor拦截器的preHandle方法,若有一个拦截器返回false,则会调用triggerAfterCompletion方法,并且立即返回,不再向下执行。若所有的拦截器全部返回true且没有出现异常,则调用Handler返回ModelAndView对象。在doDispatch方法中调用

private void triggerAfterCompletionWithError(HttpServletRequest request,HttpServletResponse response,HandlerExecutionChain mappedHandler,Error error)throws Exception,ServletException 相当于带有Error对象的triggerAfterCompletion方法。在doDispatch方法中调用

private void restoreAttributesAfterInclude(HttpServletRequest request, Map<?,?> attributesSnapshot) 恢复request请求参数的快照信息。在doService方法中调用


猜你喜欢

转载自blog.csdn.net/qq_20107237/article/details/81605180