Spring中DispatcherServlet类源码

2024-03-13 06:08

本文主要是介绍Spring中DispatcherServlet类源码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

DispatcherServlet类源码


public class DispatcherServlet extends FrameworkServlet {public static final String MULTIPART_RESOLVER_BEAN_NAME = "multipartResolver";
    public static final String LOCALE_RESOLVER_BEAN_NAME = "localeResolver";
    public static final String THEME_RESOLVER_BEAN_NAME = "themeResolver";
    public static final String HANDLER_MAPPING_BEAN_NAME = "handlerMapping";
    public static final String HANDLER_ADAPTER_BEAN_NAME = "handlerAdapter";
    public static final String HANDLER_EXCEPTION_RESOLVER_BEAN_NAME = "handlerExceptionResolver";
    public static final String REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME = "viewNameTranslator";
    public static final String VIEW_RESOLVER_BEAN_NAME = "viewResolver";
    public static final String FLASH_MAP_MANAGER_BEAN_NAME = "flashMapManager";
    public static final String WEB_APPLICATION_CONTEXT_ATTRIBUTE = DispatcherServlet.class.getName() + ".CONTEXT";
    public static final String LOCALE_RESOLVER_ATTRIBUTE = DispatcherServlet.class.getName() + ".LOCALE_RESOLVER";
    public static final String THEME_RESOLVER_ATTRIBUTE = DispatcherServlet.class.getName() + ".THEME_RESOLVER";
    public static final String THEME_SOURCE_ATTRIBUTE = DispatcherServlet.class.getName() + ".THEME_SOURCE";
    public static final String INPUT_FLASH_MAP_ATTRIBUTE = DispatcherServlet.class.getName() + ".INPUT_FLASH_MAP";
    public static final String OUTPUT_FLASH_MAP_ATTRIBUTE = DispatcherServlet.class.getName() + ".OUTPUT_FLASH_MAP";
    public static final String FLASH_MAP_MANAGER_ATTRIBUTE = DispatcherServlet.class.getName() + ".FLASH_MAP_MANAGER";
    public static final String PAGE_NOT_FOUND_LOG_CATEGORY = "org.springframework.web.servlet.PageNotFound";
    private static final String DEFAULT_STRATEGIES_PATH = "DispatcherServlet.properties";
    protected static final Log pageNotFoundLogger = LogFactory.getLog("org.springframework.web.servlet.PageNotFound");
    private static final UrlPathHelper urlPathHelper = new UrlPathHelper();
    private static final Properties defaultStrategies;
    private boolean detectAllHandlerMappings = true;
    private boolean detectAllHandlerAdapters = true;
    private boolean detectAllHandlerExceptionResolvers = true;
    private boolean detectAllViewResolvers = true;
    private boolean cleanupAfterInclude = true;
    private MultipartResolver multipartResolver;
    private LocaleResolver localeResolver;
    private ThemeResolver themeResolver;
    private List<HandlerMapping> handlerMappings;
    private List<HandlerAdapter> handlerAdapters;
    private List<HandlerExceptionResolver> handlerExceptionResolvers;
    private RequestToViewNameTranslator viewNameTranslator;
    private FlashMapManager flashMapManager;
    private List<ViewResolver> viewResolvers;

    static {try {ClassPathResource ex = new ClassPathResource("DispatcherServlet.properties", DispatcherServlet.class);
            defaultStrategies = PropertiesLoaderUtils.loadProperties(ex);
        } catch (IOException var1) {throw new IllegalStateException("Could not load \'DispatcherServlet.properties\': " + var1.getMessage());
        }}public DispatcherServlet() {}public DispatcherServlet(WebApplicationContext webApplicationContext) {super(webApplicationContext);
    }public void setDetectAllHandlerMappings(boolean detectAllHandlerMappings) {this.detectAllHandlerMappings = detectAllHandlerMappings;
    }public void setDetectAllHandlerAdapters(boolean detectAllHandlerAdapters) {this.detectAllHandlerAdapters = detectAllHandlerAdapters;
    }public void setDetectAllHandlerExceptionResolvers(boolean detectAllHandlerExceptionResolvers) {this.detectAllHandlerExceptionResolvers = detectAllHandlerExceptionResolvers;
    }public void setDetectAllViewResolvers(boolean detectAllViewResolvers) {this.detectAllViewResolvers = detectAllViewResolvers;
    }public void setCleanupAfterInclude(boolean cleanupAfterInclude) {this.cleanupAfterInclude = cleanupAfterInclude;
    }protected void onRefresh(ApplicationContext context) {this.initStrategies(context);
    }protected void initStrategies(ApplicationContext context) {this.initMultipartResolver(context);
        this.initLocaleResolver(context);
        this.initThemeResolver(context);
        this.initHandlerMappings(context);
        this.initHandlerAdapters(context);
        this.initHandlerExceptionResolvers(context);
        this.initRequestToViewNameTranslator(context);
        this.initViewResolvers(context);
        this.initFlashMapManager(context);
    }private void initMultipartResolver(ApplicationContext context) {try {this.multipartResolver = (MultipartResolver)context.getBean("multipartResolver", MultipartResolver.class);
            if(this.logger.isDebugEnabled()) {this.logger.debug("Using MultipartResolver [" + this.multipartResolver + "]");
            }} catch (NoSuchBeanDefinitionException var2) {this.multipartResolver = null;
            if(this.logger.isDebugEnabled()) {this.logger.debug("Unable to locate MultipartResolver with name \'multipartResolver\': no multipart request handling provided");
            }}}private void initLocaleResolver(ApplicationContext context) {try {this.localeResolver = (LocaleResolver)context.getBean("localeResolver", LocaleResolver.class);
            if(this.logger.isDebugEnabled()) {this.logger.debug("Using LocaleResolver [" + this.localeResolver + "]");
            }} catch (NoSuchBeanDefinitionException var2) {this.localeResolver = (LocaleResolver)this.getDefaultStrategy(context, LocaleResolver.class);
            if(this.logger.isDebugEnabled()) {this.logger.debug("Unable to locate LocaleResolver with name \'localeResolver\': using default [" + this.localeResolver + "]");
            }}}private void initThemeResolver(ApplicationContext context) {try {this.themeResolver = (ThemeResolver)context.getBean("themeResolver", ThemeResolver.class);
            if(this.logger.isDebugEnabled()) {this.logger.debug("Using ThemeResolver [" + this.themeResolver + "]");
            }} catch (NoSuchBeanDefinitionException var2) {this.themeResolver = (ThemeResolver)this.getDefaultStrategy(context, ThemeResolver.class);
            if(this.logger.isDebugEnabled()) {this.logger.debug("Unable to locate ThemeResolver with name \'themeResolver\': using default [" + this.themeResolver + "]");
            }}}private void initHandlerMappings(ApplicationContext context) {this.handlerMappings = null;
        if(this.detectAllHandlerMappings) {Map hm = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, HandlerMapping.class, true, false);
            if(!hm.isEmpty()) {this.handlerMappings = new ArrayList(hm.values());
                OrderComparator.sort(this.handlerMappings);
            }} else {try {HandlerMapping hm1 = (HandlerMapping)context.getBean("handlerMapping", HandlerMapping.class);
                this.handlerMappings = Collections.singletonList(hm1);
            } catch (NoSuchBeanDefinitionException var3) {;
            }}if(this.handlerMappings == null) {this.handlerMappings = this.getDefaultStrategies(context, HandlerMapping.class);
            if(this.logger.isDebugEnabled()) {this.logger.debug("No HandlerMappings found in servlet \'" + this.getServletName() + "\': using default");
            }}}private void initHandlerAdapters(ApplicationContext context) {this.handlerAdapters = null;
        if(this.detectAllHandlerAdapters) {Map ha = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, HandlerAdapter.class, true, false);
            if(!ha.isEmpty()) {this.handlerAdapters = new ArrayList(ha.values());
                OrderComparator.sort(this.handlerAdapters);
            }} else {try {HandlerAdapter ha1 = (HandlerAdapter)context.getBean("handlerAdapter", HandlerAdapter.class);
                this.handlerAdapters = Collections.singletonList(ha1);
            } catch (NoSuchBeanDefinitionException var3) {;
            }}if(this.handlerAdapters == null) {this.handlerAdapters = this.getDefaultStrategies(context, HandlerAdapter.class);
            if(this.logger.isDebugEnabled()) {this.logger.debug("No HandlerAdapters found in servlet \'" + this.getServletName() + "\': using default");
            }}}private void initHandlerExceptionResolvers(ApplicationContext context) {this.handlerExceptionResolvers = null;
        if(this.detectAllHandlerExceptionResolvers) {Map her = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, HandlerExceptionResolver.class, true, false);
            if(!her.isEmpty()) {this.handlerExceptionResolvers = new ArrayList(her.values());
                OrderComparator.sort(this.handlerExceptionResolvers);
            }} else {try {HandlerExceptionResolver her1 = (HandlerExceptionResolver)context.getBean("handlerExceptionResolver", HandlerExceptionResolver.class);
                this.handlerExceptionResolvers = Collections.singletonList(her1);
            } catch (NoSuchBeanDefinitionException var3) {;
            }}if(this.handlerExceptionResolvers == null) {this.handlerExceptionResolvers = this.getDefaultStrategies(context, HandlerExceptionResolver.class);
            if(this.logger.isDebugEnabled()) {this.logger.debug("No HandlerExceptionResolvers found in servlet \'" + this.getServletName() + "\': using default");
            }}}private void initRequestToViewNameTranslator(ApplicationContext context) {try {this.viewNameTranslator = (RequestToViewNameTranslator)context.getBean("viewNameTranslator", RequestToViewNameTranslator.class);
            if(this.logger.isDebugEnabled()) {this.logger.debug("Using RequestToViewNameTranslator [" + this.viewNameTranslator + "]");
            }} catch (NoSuchBeanDefinitionException var2) {this.viewNameTranslator = (RequestToViewNameTranslator)this.getDefaultStrategy(context, RequestToViewNameTranslator.class);
            if(this.logger.isDebugEnabled()) {this.logger.debug("Unable to locate RequestToViewNameTranslator with name \'viewNameTranslator\': using default [" + this.viewNameTranslator + "]");
            }}}private void initViewResolvers(ApplicationContext context) {this.viewResolvers = null;
        if(this.detectAllViewResolvers) {Map vr = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, ViewResolver.class, true, false);
            if(!vr.isEmpty()) {this.viewResolvers = new ArrayList(vr.values());
                OrderComparator.sort(this.viewResolvers);
            }} else {try {ViewResolver vr1 = (ViewResolver)context.getBean("viewResolver", ViewResolver.class);
                this.viewResolvers = Collections.singletonList(vr1);
            } catch (NoSuchBeanDefinitionException var3) {;
            }}if(this.viewResolvers == null) {this.viewResolvers = this.getDefaultStrategies(context, ViewResolver.class);
            if(this.logger.isDebugEnabled()) {this.logger.debug("No ViewResolvers found in servlet \'" + this.getServletName() + "\': using default");
            }}}private void initFlashMapManager(ApplicationContext context) {try {this.flashMapManager = (FlashMapManager)context.getBean("flashMapManager", FlashMapManager.class);
            if(this.logger.isDebugEnabled()) {this.logger.debug("Using FlashMapManager [" + this.flashMapManager + "]");
            }} catch (NoSuchBeanDefinitionException var2) {this.flashMapManager = (FlashMapManager)this.getDefaultStrategy(context, FlashMapManager.class);
            if(this.logger.isDebugEnabled()) {this.logger.debug("Unable to locate FlashMapManager with name \'flashMapManager\': using default [" + this.flashMapManager + "]");
            }}}public final ThemeSource getThemeSource() {return this.getWebApplicationContext() instanceof ThemeSource?(ThemeSource)this.getWebApplicationContext():null;
    }public final MultipartResolver getMultipartResolver() {return this.multipartResolver;
    }protected <T> T getDefaultStrategy(ApplicationContext context, Class<T> strategyInterface) {List strategies = this.getDefaultStrategies(context, strategyInterface);
        if(strategies.size() != 1) {throw new BeanInitializationException("DispatcherServlet needs exactly 1 strategy for interface [" + strategyInterface.getName() + "]");
        } else {return strategies.get(0);
        }}protected <T> List<T> getDefaultStrategies(ApplicationContext context, Class<T> strategyInterface) {String key = strategyInterface.getName();
        String value = defaultStrategies.getProperty(key);
        if(value == null) {return new LinkedList();
        } else {String[] classNames = StringUtils.commaDelimitedListToStringArray(value);
            ArrayList strategies = new ArrayList(classNames.length);
            String[] var10 = classNames;
            int var9 = classNames.length;

            for(int var8 = 0; var8 < var9; ++var8) {String className = var10[var8];

                try {Class err = ClassUtils.forName(className, DispatcherServlet.class.getClassLoader());
                    Object strategy = this.createDefaultStrategy(context, err);
                    strategies.add(strategy);
                } catch (ClassNotFoundException var13) {throw new BeanInitializationException("Could not find DispatcherServlet\'s default strategy class [" + className + "] for interface [" + key + "]", var13);
                } catch (LinkageError var14) {throw new BeanInitializationException("Error loading DispatcherServlet\'s default strategy class [" + className + "] for interface [" + key + "]: problem with class file or dependent class", var14);
                }}return strategies;
        }}protected Object createDefaultStrategy(ApplicationContext context, Class<?> clazz) {return context.getAutowireCapableBeanFactory().createBean(clazz);
    }protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {if(this.logger.isDebugEnabled()) {String attributesSnapshot = urlPathHelper.getRequestUri(request);
            this.logger.debug("DispatcherServlet with name \'" + this.getServletName() + "\' processing " + request.getMethod() + " request for [" + attributesSnapshot + "]");
        }HashMap attributesSnapshot1 = null;
        if(WebUtils.isIncludeRequest(request)) {this.logger.debug("Taking snapshot of request attributes before include");
            attributesSnapshot1 = new HashMap();
            Enumeration inputFlashMap = request.getAttributeNames();

            label90:while(true) {String attrName;
                do {if(!inputFlashMap.hasMoreElements()) {break label90;
                    }attrName = (String)inputFlashMap.nextElement();
                } while(!this.cleanupAfterInclude && !attrName.startsWith("org.springframework.web.servlet"));

                attributesSnapshot1.put(attrName, request.getAttribute(attrName));
            }}request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.getWebApplicationContext());
        request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver);
        request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver);
        request.setAttribute(THEME_SOURCE_ATTRIBUTE, this.getThemeSource());
        FlashMap inputFlashMap1 = this.flashMapManager.retrieveAndUpdate(request, response);
        if(inputFlashMap1 != null) {request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap1));
        }request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
        request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager);

        try {this.doDispatch(request, response);
        } finally {if(attributesSnapshot1 != null) {this.restoreAttributesAfterInclude(request, attributesSnapshot1);
            }}}protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {HttpServletRequest processedRequest = request;
        HandlerExecutionChain mappedHandler = null;
        int interceptorIndex = -1;

        try {boolean var25 = false;

            ModelAndView err;
            try {processedRequest = this.checkMultipart(request);
                mappedHandler = this.getHandler(processedRequest, false);
                if(mappedHandler == null || mappedHandler.getHandler() == null) {this.noHandlerFound(processedRequest, response);
                    return;
                }HandlerAdapter ex1 = this.getHandlerAdapter(mappedHandler.getHandler());
                String var26 = request.getMethod();
                boolean isGet = "GET".equals(var26);
                if(isGet || "HEAD".equals(var26)) {long interceptors = ex1.getLastModified(request, mappedHandler.getHandler());
                    if(this.logger.isDebugEnabled()) {String interceptor = urlPathHelper.getRequestUri(request);
                        this.logger.debug("Last-Modified value for [" + interceptor + "] is: " + interceptors);
                    }if((new ServletWebRequest(request, response)).checkNotModified(interceptors) && isGet) {return;
                    }}HandlerInterceptor[] var27 = mappedHandler.getInterceptors();
                int i;
                HandlerInterceptor var28;
                if(var27 != null) {for(i = 0; i < var27.length; interceptorIndex = i++) {var28 = var27[i];
                        if(!var28.preHandle(processedRequest, response, mappedHandler.getHandler())) {this.triggerAfterCompletion(mappedHandler, interceptorIndex, processedRequest, response, (Exception)null);
                            return;
                        }}}err = ex1.handle(processedRequest, response, mappedHandler.getHandler());
                if(err != null && !err.hasView()) {err.setViewName(this.getDefaultViewName(request));
                }if(var27 != null) {for(i = var27.length - 1; i >= 0; --i) {var28 = var27[i];
                        var28.postHandle(processedRequest, response, mappedHandler.getHandler(), err);
                    }}} catch (ModelAndViewDefiningException var20) {this.logger.debug("ModelAndViewDefiningException encountered", var20);
                err = var20.getModelAndView();
            } catch (Exception var21) {Object handler = mappedHandler != null?mappedHandler.getHandler():null;
                err = this.processHandlerException(processedRequest, response, handler, var21);
                var25 = err != null;
            }if(err != null && !err.wasCleared()) {this.render(err, processedRequest, response);
                if(var25) {WebUtils.clearErrorRequestAttributes(request);
                }} else if(this.logger.isDebugEnabled()) {this.logger.debug("Null ModelAndView returned to DispatcherServlet with name \'" + this.getServletName() + "\': assuming HandlerAdapter completed request handling");
            }this.triggerAfterCompletion(mappedHandler, interceptorIndex, processedRequest, response, (Exception)null);
        } catch (Exception var22) {this.triggerAfterCompletion(mappedHandler, interceptorIndex, processedRequest, response, var22);
            throw var22;
        } catch (Error var23) {NestedServletException ex = new NestedServletException("Handler processing failed", var23);
            this.triggerAfterCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex);
            throw ex;
        } finally {if(processedRequest != request) {this.cleanupMultipart(processedRequest);
            }}}protected LocaleContext buildLocaleContext(final HttpServletRequest request) {return new LocaleContext() {public Locale getLocale() {return DispatcherServlet.this.localeResolver.resolveLocale(request);
            }public String toString() {return this.getLocale().toString();
            }};
    }protected HttpServletRequest checkMultipart(HttpServletRequest request) throws MultipartException {if(this.multipartResolver != null && this.multipartResolver.isMultipart(request)) {if(!(request instanceof MultipartHttpServletRequest)) {return this.multipartResolver.resolveMultipart(request);
            }this.logger.debug("Request is already a MultipartHttpServletRequest - if not in a forward, this typically results from an additional MultipartFilter in web.xml");
        }return request;
    }protected void cleanupMultipart(HttpServletRequest request) {if(request instanceof MultipartHttpServletRequest) {this.multipartResolver.cleanupMultipart((MultipartHttpServletRequest)request);
        }}/** @deprecated */
    @Deprecatedprotected HandlerExecutionChain getHandler(HttpServletRequest request, boolean cache) throws Exception {return this.getHandler(request);
    }protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {Iterator var3 = this.handlerMappings.iterator();

        HandlerExecutionChain handler;
        do {if(!var3.hasNext()) {return null;
            }HandlerMapping hm = (HandlerMapping)var3.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;
    }protected void noHandlerFound(HttpServletRequest request, HttpServletResponse response) throws Exception {if(pageNotFoundLogger.isWarnEnabled()) {String requestUri = urlPathHelper.getRequestUri(request);
            pageNotFoundLogger.warn("No mapping found for HTTP request with URI [" + requestUri + "] in DispatcherServlet with name \'" + this.getServletName() + "\'");
        }response.sendError(404);
    }protected HandlerAdapter getHandlerAdapter(Object handler) throws ServletException {Iterator var3 = this.handlerAdapters.iterator();

        HandlerAdapter ha;
        do {if(!var3.hasNext()) {throw new ServletException("No adapter for handler [" + handler + "]: Does your handler implement a supported interface like Controller?");
            }ha = (HandlerAdapter)var3.next();
            if(this.logger.isTraceEnabled()) {this.logger.trace("Testing handler adapter [" + ha + "]");
            }} while(!ha.supports(handler));

        return ha;
    }protected ModelAndView processHandlerException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {ModelAndView exMv = null;
        Iterator var7 = this.handlerExceptionResolvers.iterator();

        while(var7.hasNext()) {HandlerExceptionResolver handlerExceptionResolver = (HandlerExceptionResolver)var7.next();
            exMv = handlerExceptionResolver.resolveException(request, response, handler, ex);
            if(exMv != null) {break;
            }}if(exMv != null) {if(exMv.isEmpty()) {return null;
            } else {if(!exMv.hasView()) {exMv.setViewName(this.getDefaultViewName(request));
                }if(this.logger.isDebugEnabled()) {this.logger.debug("Handler execution resulted in exception - forwarding to resolved error view: " + exMv, ex);
                }WebUtils.exposeErrorRequestAttributes(request, ex, this.getServletName());
                return exMv;
            }} else {throw ex;
        }}protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response) throws Exception {Locale locale = this.localeResolver.resolveLocale(request);
        response.setLocale(locale);
        View view;
        if(mv.isReference()) {view = this.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 \'" + this.getServletName() + "\'");
            }} else {view = mv.getView();
            if(view == null) {throw new ServletException("ModelAndView [" + mv + "] neither contains a view name nor a " + "View object in servlet with name \'" + this.getServletName() + "\'");
            }}if(this.logger.isDebugEnabled()) {this.logger.debug("Rendering view [" + view + "] in DispatcherServlet with name \'" + this.getServletName() + "\'");
        }view.render(mv.getModelInternal(), request, response);
    }protected String getDefaultViewName(HttpServletRequest request) throws Exception {return this.viewNameTranslator.getViewName(request);
    }protected View resolveViewName(String viewName, Map<String, Object> model, Locale locale, HttpServletRequest request) throws Exception {Iterator var6 = this.viewResolvers.iterator();

        while(var6.hasNext()) {ViewResolver viewResolver = (ViewResolver)var6.next();
            View view = viewResolver.resolveViewName(viewName, locale);
            if(view != null) {return view;
            }}return null;
    }private void triggerAfterCompletion(HandlerExecutionChain mappedHandler, int interceptorIndex, HttpServletRequest request, HttpServletResponse response, Exception ex) throws Exception {if(mappedHandler != null) {HandlerInterceptor[] interceptors = mappedHandler.getInterceptors();
            if(interceptors != null) {for(int i = interceptorIndex; i >= 0; --i) {HandlerInterceptor interceptor = interceptors[i];

                    try {interceptor.afterCompletion(request, response, mappedHandler.getHandler(), ex);
                    } catch (Throwable var10) {this.logger.error("HandlerInterceptor.afterCompletion threw exception", var10);
                    }}}}}private void restoreAttributesAfterInclude(HttpServletRequest request, Map<?, ?> attributesSnapshot) {this.logger.debug("Restoring snapshot of request attributes after include");
        HashSet attrsToCheck = new HashSet();
        Enumeration attrNames = request.getAttributeNames();

        while(true) {String attrName;
            do {if(!attrNames.hasMoreElements()) {Iterator var6 = attrsToCheck.iterator();

                    while(var6.hasNext()) {attrName = (String)var6.next();
                        Object attrValue = attributesSnapshot.get(attrName);
                        if(attrValue == null) {if(this.logger.isDebugEnabled()) {this.logger.debug("Removing attribute [" + attrName + "] after include");
                            }request.removeAttribute(attrName);
                        } else if(attrValue != request.getAttribute(attrName)) {if(this.logger.isDebugEnabled()) {this.logger.debug("Restoring original value of attribute [" + attrName + "] after include");
                            }request.setAttribute(attrName, attrValue);
                        }}return;
                }attrName = (String)attrNames.nextElement();
            } while(!this.cleanupAfterInclude && !attrName.startsWith("org.springframework.web.servlet"));

            attrsToCheck.add(attrName);
        }}
}

这篇关于Spring中DispatcherServlet类源码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/803861

相关文章

Java实战之利用POI生成Excel图表

《Java实战之利用POI生成Excel图表》ApachePOI是Java生态中处理Office文档的核心工具,这篇文章主要为大家详细介绍了如何在Excel中创建折线图,柱状图,饼图等常见图表,需要的... 目录一、环境配置与依赖管理二、数据源准备与工作表构建三、图表生成核心步骤1. 折线图(Line Ch

Spring Boot 3 整合 Spring Cloud Gateway实践过程

《SpringBoot3整合SpringCloudGateway实践过程》本文介绍了如何使用SpringCloudAlibaba2023.0.0.0版本构建一个微服务网关,包括统一路由、限... 目录引子为什么需要微服务网关实践1.统一路由2.限流防刷3.登录鉴权小结引子当前微服务架构已成为中大型系统的标

Java集合中的List超详细讲解

《Java集合中的List超详细讲解》本文详细介绍了Java集合框架中的List接口,包括其在集合中的位置、继承体系、常用操作和代码示例,以及不同实现类(如ArrayList、LinkedList和V... 目录一,List的继承体系二,List的常用操作及代码示例1,创建List实例2,增加元素3,访问元

Java中将异步调用转为同步的五种实现方法

《Java中将异步调用转为同步的五种实现方法》本文介绍了将异步调用转为同步阻塞模式的五种方法:wait/notify、ReentrantLock+Condition、Future、CountDownL... 目录异步与同步的核心区别方法一:使用wait/notify + synchronized代码示例关键

Java 8 Stream filter流式过滤器详解

《Java8Streamfilter流式过滤器详解》本文介绍了Java8的StreamAPI中的filter方法,展示了如何使用lambda表达式根据条件过滤流式数据,通过实际代码示例,展示了f... 目录引言 一.Java 8 Stream 的过滤器(filter)二.Java 8 的 filter、fi

Java中实现订单超时自动取消功能(最新推荐)

《Java中实现订单超时自动取消功能(最新推荐)》本文介绍了Java中实现订单超时自动取消功能的几种方法,包括定时任务、JDK延迟队列、Redis过期监听、Redisson分布式延迟队列、Rocket... 目录1、定时任务2、JDK延迟队列 DelayQueue(1)定义实现Delayed接口的实体类 (

springboot的调度服务与异步服务使用详解

《springboot的调度服务与异步服务使用详解》本文主要介绍了Java的ScheduledExecutorService接口和SpringBoot中如何使用调度线程池,包括核心参数、创建方式、自定... 目录1.调度服务1.1.JDK之ScheduledExecutorService1.2.spring

将java程序打包成可执行文件的实现方式

《将java程序打包成可执行文件的实现方式》本文介绍了将Java程序打包成可执行文件的三种方法:手动打包(将编译后的代码及JRE运行环境一起打包),使用第三方打包工具(如Launch4j)和JDK自带... 目录1.问题提出2.如何将Java程序打包成可执行文件2.1将编译后的代码及jre运行环境一起打包2

Java使用Tesseract-OCR实战教程

《Java使用Tesseract-OCR实战教程》本文介绍了如何在Java中使用Tesseract-OCR进行文本提取,包括Tesseract-OCR的安装、中文训练库的配置、依赖库的引入以及具体的代... 目录Java使用Tesseract-OCRTesseract-OCR安装配置中文训练库引入依赖代码实

Java中对象的创建和销毁过程详析

《Java中对象的创建和销毁过程详析》:本文主要介绍Java中对象的创建和销毁过程,对象的创建过程包括类加载检查、内存分配、初始化零值内存、设置对象头和执行init方法,对象的销毁过程由垃圾回收机... 目录前言对象的创建过程1. 类加载检查2China编程. 分配内存3. 初始化零值4. 设置对象头5. 执行