DispatcherServlet class explanation
=================The following are some translations of class definitions and class annotations, which still need to be modified. =================
/**
"serial" DispatcherServlet
}
========================The following are some of the more important attributes of this class========== ===============
/** MultipartResolver used by this servlet */private MultipartResolver multipartResolver; /** LocaleResolver used by this servlet */private LocaleResolver localeResolver;/** ThemeResolver used by this servlet */private ThemeResolver themeResolver;/** List of HandlerMappings used by this servlet */private List<HandlerMapping> handlerMappings; //处理器映射列表/** List of HandlerAdapters used by this servlet */private List<HandlerAdapter> handlerAdapters; //处理器适配器列表/** List of HandlerExceptionResolvers used by this servlet */private List<HandlerExceptionResolver> handlerExceptionResolvers; //处理器异常解析器列表/** RequestToViewNameTranslator used by this servlet */private RequestToViewNameTranslator viewNameTranslator;/** FlashMapManager used by this servlet */private FlashMapManager flashMapManager;/** List of ViewResolvers used by this servlet */private List<ViewResolver> viewResolvers; //视图解析器列表
========== ==================The following is the parameterless constructor of the class================== ==========
<span style="color: #008000">/**</span><span style="color: #008000"> * Create a new {</span><span style="color: #808080">@code</span><span style="color: #008000"> DispatcherServlet} that will create its own internal web * application context based on defaults and values provided through servlet * init-params. Typically used in Servlet 2.5 or earlier environments, where the only * option for servlet registration is through {</span><span style="color: #808080">@code</span><span style="color: #008000"> web.xml} which requires the use * of a no-arg constructor. * <p>Calling {</span><span style="color: #808080">@link</span><span style="color: #008000"> #setContextConfigLocation} (init-param 'contextConfigLocation') * will dictate which XML files will be loaded by the * {</span><span style="color: #808080">@linkplain</span><span style="color: #008000"> #DEFAULT_CONTEXT_CLASS default XmlWebApplicationContext} * <p>Calling {</span><span style="color: #808080">@link</span><span style="color: #008000"> #setContextClass} (init-param 'contextClass') overrides the * default {</span><span style="color: #808080">@code</span><span style="color: #008000"> XmlWebApplicationContext} and allows for specifying an alternative class, * such as {</span><span style="color: #808080">@code</span><span style="color: #008000"> AnnotationConfigWebApplicationContext}. * <p>Calling {</span><span style="color: #808080">@link</span><span style="color: #008000"> #setContextInitializerClasses} (init-param 'contextInitializerClasses') * indicates which {</span><span style="color: #808080">@code</span><span style="color: #008000"> ApplicationContextInitializer} classes should be used to * further configure the internal application context prior to refresh(). * </span><span style="color: #808080">@see</span><span style="color: #008000"> #DispatcherServlet(WebApplicationContext)<br> * </span><span style="color: #008000">*/</span><span style="color: #0000ff">public</span><span style="color: #000000"> DispatcherServlet() {</span><span style="color: #0000ff">super</span><span style="color: #000000">(); setDispatchOptionsRequest(</span><span style="color: #0000ff">true</span><span style="color: #000000">); }</span>
================= Below It is the initStrategies(ApplicationContext context) method ==================
which is mainly used to initialize some of the important attributes mentioned above.
//初始化这个DispatcherServlet使用到的策略对象。这个方法有可能会被子类覆盖。protected void initStrategies(ApplicationContext context) { initMultipartResolver(context); initLocaleResolver(context); initThemeResolver(context);
/* * * */ initHandlerMappings(context);
initHandlerExceptionResolvers(context); initRequestToViewNameTranslator(context); initViewResolvers(context); initFlashMapManager(context); }
========================The following is DispatherDoService() method of Servlet==================
doService(HttpServletRequest request, HttpServletResponse response) = WebAsyncUtils.getAsyncManager(request).hasConcurrentResult() ? " resumed" : """DispatcherServlet with name '" + getServletName() + "'" + resumed + " processing " + request.getMethod() + " request for [" + getRequestUri(request) + "]"<String, Object> attributesSnapshot = = HashMap<String, Object><?> attrNames == (.cleanupAfterInclude || attrName.startsWith("org.springframework.web.servlet"= (inputFlashMap != (! (attributesSnapshot !=
================================================== ========================
doDispatch(HttpServletRequest request, HttpServletResponse response) == multipartRequestParsed = WebAsyncManager asyncManager == = processedRequest == (processedRequest !=mappedHandler = (mappedHandler == || mappedHandler.getHandler() == HandlerAdapter ha =String method = isGet = "GET" (isGet || "HEAD" lastModified ="Last-Modified value for [" + getRequestUri(request) + "] is: " + ( ServletWebRequest(request, response).checkNotModified(lastModified) && (!mv ==dispatchException = NestedServletException("Handler dispatch failed" NestedServletException("Handler processing failed" (mappedHandler !=
= ================================================== ======================
/** * 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 handler could be found */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; }
================ ================================================== ========
/** * Render the given ModelAndView. * <p>This is the last stage in handling a request. It may involve resolving the view by name. * @param mv the ModelAndView to render * @param request current HTTP servlet request * @param response current HTTP servlet response * @throws ServletException if view is missing or cannot be resolved * @throws Exception if there's a problem rendering the view */protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response) throws Exception {// Determine locale for request and apply it to the response.Locale locale = this.localeResolver.resolveLocale(request); response.setLocale(locale); View view;if (mv.isReference()) {// We need to resolve the view name.view = resolveViewName(mv.getViewName(), mv.getModelInternal(), locale, request);if (view == null) {throw new ServletException("Could not resolve view with name '" + mv.getViewName() + "' in servlet with name '" + getServletName() + "'"); } }else {// No need to lookup: the ModelAndView object contains the actual View object.view = mv.getView();if (view == null) {throw new ServletException("ModelAndView [" + mv + "] neither contains a view name nor a " + "View object in servlet with name '" + getServletName() + "'"); } }// Delegate to the View object for rendering.if (logger.isDebugEnabled()) { logger.debug("Rendering view [" + view + "] in DispatcherServlet with name '" + getServletName() + "'"); }try {if (mv.getStatus() != null) { response.setStatus(mv.getStatus().value()); } view.render(mv.getModelInternal(), request, response); }catch (Exception ex) {if (logger.isDebugEnabled()) { logger.debug("Error rendering view [" + view + "] in DispatcherServlet with name '" +getServletName() + "'", ex); }throw ex; } }
======================== ==================================================
/** * Resolve the given view name into a View object (to be rendered). * <p>The default implementations asks all ViewResolvers of this dispatcher. * Can be overridden for custom resolution strategies, potentially based on * specific model attributes or request parameters. * @param viewName the name of the view to resolve * @param model the model to be passed to the view * @param locale the current locale * @param request current HTTP servlet request * @return the View object, or {@code null} if none found * @throws Exception if the view cannot be resolved * (typically in case of problems creating an actual View object) * @see ViewResolver#resolveViewName */protected View resolveViewName(String viewName, Map<String, Object> model, Locale locale, HttpServletRequest request) throws Exception {for (ViewResolver viewResolver : this.viewResolvers) { View view = viewResolver.resolveViewName(viewName, locale);if (view != null) {return view; } }return null; }
================================== ==========================================
== ================================================== =====================
======================== ==================================================
============================================== =============================
================ ================================================== ========
The above is the detailed content of DispatcherServlet class explanation. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use MySQL database for forecasting and predictive analytics? Overview: Forecasting and predictive analytics play an important role in data analysis. MySQL, a widely used relational database management system, can also be used for prediction and predictive analysis tasks. This article will introduce how to use MySQL for prediction and predictive analysis, and provide relevant code examples. Data preparation: First, we need to prepare relevant data. Suppose we want to do sales forecasting, we need a table with sales data. In MySQL we can use

How to implement data statistics and analysis in uniapp 1. Background introduction Data statistics and analysis are a very important part of the mobile application development process. Through statistics and analysis of user behavior, developers can have an in-depth understanding of user preferences and usage habits. Thereby optimizing product design and user experience. This article will introduce how to implement data statistics and analysis functions in uniapp, and provide some specific code examples. 2. Choose appropriate data statistics and analysis tools. The first step to implement data statistics and analysis in uniapp is to choose the appropriate data statistics and analysis tools.

With the advent of the big data era, data visualization analysis plays a vital role in all walks of life. As a fast, efficient and safe programming language, Go language has gradually occupied a place in the field of data visualization analysis. This article will explore how to use Go language for data visualization analysis. 1. Plotly, a commonly used data visualization library in Go language: can be used to create interactive graphics in the browser and supports a variety of graphics types, such as line graphs, bar graphs, scatter plots, heat maps, etc. Gonum/plo

Real-time log monitoring and analysis under Linux In daily system management and troubleshooting, logs are a very important data source. Through real-time monitoring and analysis of system logs, we can detect abnormal situations in time and handle them accordingly. This article will introduce how to perform real-time log monitoring and analysis under Linux, and provide corresponding code examples. 1. Real-time log monitoring Under Linux, the most commonly used log system is rsyslog. By configuring rsyslog, we can combine the logs of different applications

Title: Analysis of the reasons and solutions for why the secondary directory of DreamWeaver CMS cannot be opened. Dreamweaver CMS (DedeCMS) is a powerful open source content management system that is widely used in the construction of various websites. However, sometimes during the process of building a website, you may encounter a situation where the secondary directory cannot be opened, which brings trouble to the normal operation of the website. In this article, we will analyze the possible reasons why the secondary directory cannot be opened and provide specific code examples to solve this problem. 1. Possible cause analysis: Pseudo-static rule configuration problem: during use

Statistical analysis often refers to the process of sorting, classifying and interpreting collected relevant data. The basic steps of statistical analysis include: 1. Collect data; 2. Organize data; 3. Analyze data.

ThinkPHP6 code performance analysis: locating performance bottlenecks Introduction: With the rapid development of the Internet, more efficient code performance analysis has become increasingly important for developers. This article will introduce how to use ThinkPHP6 to perform code performance analysis in order to locate and solve performance bottlenecks. At the same time, we will also use code examples to help readers understand better. Importance of Performance Analysis Code performance analysis is an integral part of the development process. By analyzing the performance of the code, we can understand where a lot of resources are consumed

Performance analysis and optimization strategies of TP6Think-SwooleRPC service Summary: This article mainly analyzes the performance of TP6 and Think-SwooleRPC services, and proposes some optimization strategies. First, the response time, concurrency and throughput of the RPC service were evaluated through performance testing. Then, corresponding solutions and practices are proposed from two aspects: server-side performance optimization and client-side performance optimization, including code examples. Keywords: TP6, Think-Swoole, R
