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

相关文章

SpringBoot整合Flowable实现工作流的详细流程

《SpringBoot整合Flowable实现工作流的详细流程》Flowable是一个使用Java编写的轻量级业务流程引擎,Flowable流程引擎可用于部署BPMN2.0流程定义,创建这些流程定义的... 目录1、流程引擎介绍2、创建项目3、画流程图4、开发接口4.1 Java 类梳理4.2 查看流程图4

一文详解如何在idea中快速搭建一个Spring Boot项目

《一文详解如何在idea中快速搭建一个SpringBoot项目》IntelliJIDEA作为Java开发者的‌首选IDE‌,深度集成SpringBoot支持,可一键生成项目骨架、智能配置依赖,这篇文... 目录前言1、创建项目名称2、勾选需要的依赖3、在setting中检查maven4、编写数据源5、开启热

Java对异常的认识与异常的处理小结

《Java对异常的认识与异常的处理小结》Java程序在运行时可能出现的错误或非正常情况称为异常,下面给大家介绍Java对异常的认识与异常的处理,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参... 目录一、认识异常与异常类型。二、异常的处理三、总结 一、认识异常与异常类型。(1)简单定义-什么是

SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志

《SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志》在SpringBoot项目中,使用logback-spring.xml配置屏蔽特定路径的日志有两种常用方式,文中的... 目录方案一:基础配置(直接关闭目标路径日志)方案二:结合 Spring Profile 按环境屏蔽关

Java使用HttpClient实现图片下载与本地保存功能

《Java使用HttpClient实现图片下载与本地保存功能》在当今数字化时代,网络资源的获取与处理已成为软件开发中的常见需求,其中,图片作为网络上最常见的资源之一,其下载与保存功能在许多应用场景中都... 目录引言一、Apache HttpClient简介二、技术栈与环境准备三、实现图片下载与保存功能1.

SpringBoot排查和解决JSON解析错误(400 Bad Request)的方法

《SpringBoot排查和解决JSON解析错误(400BadRequest)的方法》在开发SpringBootRESTfulAPI时,客户端与服务端的数据交互通常使用JSON格式,然而,JSON... 目录问题背景1. 问题描述2. 错误分析解决方案1. 手动重新输入jsON2. 使用工具清理JSON3.

java中long的一些常见用法

《java中long的一些常见用法》在Java中,long是一种基本数据类型,用于表示长整型数值,接下来通过本文给大家介绍java中long的一些常见用法,感兴趣的朋友一起看看吧... 在Java中,long是一种基本数据类型,用于表示长整型数值。它的取值范围比int更大,从-922337203685477

java Long 与long之间的转换流程

《javaLong与long之间的转换流程》Long类提供了一些方法,用于在long和其他数据类型(如String)之间进行转换,本文将详细介绍如何在Java中实现Long和long之间的转换,感... 目录概述流程步骤1:将long转换为Long对象步骤2:将Longhttp://www.cppcns.c

SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程

《SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程》LiteFlow是一款专注于逻辑驱动流程编排的轻量级框架,它以组件化方式快速构建和执行业务流程,有效解耦复杂业务逻辑,下面给大... 目录一、基础概念1.1 组件(Component)1.2 规则(Rule)1.3 上下文(Conte

SpringBoot服务获取Pod当前IP的两种方案

《SpringBoot服务获取Pod当前IP的两种方案》在Kubernetes集群中,SpringBoot服务获取Pod当前IP的方案主要有两种,通过环境变量注入或通过Java代码动态获取网络接口IP... 目录方案一:通过 Kubernetes Downward API 注入环境变量原理步骤方案二:通过