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

相关文章

Spring Boot集成Druid实现数据源管理与监控的详细步骤

《SpringBoot集成Druid实现数据源管理与监控的详细步骤》本文介绍如何在SpringBoot项目中集成Druid数据库连接池,包括环境搭建、Maven依赖配置、SpringBoot配置文件... 目录1. 引言1.1 环境准备1.2 Druid介绍2. 配置Druid连接池3. 查看Druid监控

Java中读取YAML文件配置信息常见问题及解决方法

《Java中读取YAML文件配置信息常见问题及解决方法》:本文主要介绍Java中读取YAML文件配置信息常见问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要... 目录1 使用Spring Boot的@ConfigurationProperties2. 使用@Valu

创建Java keystore文件的完整指南及详细步骤

《创建Javakeystore文件的完整指南及详细步骤》本文详解Java中keystore的创建与配置,涵盖私钥管理、自签名与CA证书生成、SSL/TLS应用,强调安全存储及验证机制,确保通信加密和... 目录1. 秘密键(私钥)的理解与管理私钥的定义与重要性私钥的管理策略私钥的生成与存储2. 证书的创建与

浅析Spring如何控制Bean的加载顺序

《浅析Spring如何控制Bean的加载顺序》在大多数情况下,我们不需要手动控制Bean的加载顺序,因为Spring的IoC容器足够智能,但在某些特殊场景下,这种隐式的依赖关系可能不存在,下面我们就来... 目录核心原则:依赖驱动加载手动控制 Bean 加载顺序的方法方法 1:使用@DependsOn(最直

SpringBoot中如何使用Assert进行断言校验

《SpringBoot中如何使用Assert进行断言校验》Java提供了内置的assert机制,而Spring框架也提供了更强大的Assert工具类来帮助开发者进行参数校验和状态检查,下... 目录前言一、Java 原生assert简介1.1 使用方式1.2 示例代码1.3 优缺点分析二、Spring Fr

java使用protobuf-maven-plugin的插件编译proto文件详解

《java使用protobuf-maven-plugin的插件编译proto文件详解》:本文主要介绍java使用protobuf-maven-plugin的插件编译proto文件,具有很好的参考价... 目录protobuf文件作为数据传输和存储的协议主要介绍在Java使用maven编译proto文件的插件

Java中的数组与集合基本用法详解

《Java中的数组与集合基本用法详解》本文介绍了Java数组和集合框架的基础知识,数组部分涵盖了一维、二维及多维数组的声明、初始化、访问与遍历方法,以及Arrays类的常用操作,对Java数组与集合相... 目录一、Java数组基础1.1 数组结构概述1.2 一维数组1.2.1 声明与初始化1.2.2 访问

Javaee多线程之进程和线程之间的区别和联系(最新整理)

《Javaee多线程之进程和线程之间的区别和联系(最新整理)》进程是资源分配单位,线程是调度执行单位,共享资源更高效,创建线程五种方式:继承Thread、Runnable接口、匿名类、lambda,r... 目录进程和线程进程线程进程和线程的区别创建线程的五种写法继承Thread,重写run实现Runnab

Java 方法重载Overload常见误区及注意事项

《Java方法重载Overload常见误区及注意事项》Java方法重载允许同一类中同名方法通过参数类型、数量、顺序差异实现功能扩展,提升代码灵活性,核心条件为参数列表不同,不涉及返回类型、访问修饰符... 目录Java 方法重载(Overload)详解一、方法重载的核心条件二、构成方法重载的具体情况三、不构

Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式

《Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式》本文详细介绍如何使用Java通过JDBC连接MySQL数据库,包括下载驱动、配置Eclipse环境、检测数据库连接等关键步骤,... 目录一、下载驱动包二、放jar包三、检测数据库连接JavaJava 如何使用 JDBC 连接 mys