所在类:org.springframework.web.servlet.DispatcherServlet

    1. protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
    2. this.logRequest(request);
    3. Map<String, Object> attributesSnapshot = null;
    4. if (WebUtils.isIncludeRequest(request)) {
    5. attributesSnapshot = new HashMap();
    6. Enumeration attrNames = request.getAttributeNames();
    7. label120:
    8. while(true) {
    9. String attrName;
    10. do {
    11. if (!attrNames.hasMoreElements()) {
    12. break label120;
    13. }
    14. attrName = (String)attrNames.nextElement();
    15. } while(!this.cleanupAfterInclude && !attrName.startsWith("org.springframework.web.servlet"));
    16. attributesSnapshot.put(attrName, request.getAttribute(attrName));
    17. }
    18. }
    19. request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.getWebApplicationContext());
    20. request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver);
    21. request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver);
    22. request.setAttribute(THEME_SOURCE_ATTRIBUTE, this.getThemeSource());
    23. if (this.flashMapManager != null) {
    24. FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(request, response);
    25. if (inputFlashMap != null) {
    26. request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap));
    27. }
    28. request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
    29. request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager);
    30. }
    31. RequestPath requestPath = null;
    32. if (this.parseRequestPath && !ServletRequestPathUtils.hasParsedRequestPath(request)) {
    33. requestPath = ServletRequestPathUtils.parseAndCache(request);
    34. }
    35. try {
    36. this.doDispatch(request, response);
    37. } finally {
    38. if (!WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted() && attributesSnapshot != null) {
    39. this.restoreAttributesAfterInclude(request, attributesSnapshot);
    40. }
    41. if (requestPath != null) {
    42. ServletRequestPathUtils.clearParsedRequestPath(request);
    43. }
    44. }
    45. }