public abstract class

RequestContextUtils

extends Object
java.lang.Object
   ↳ org.springframework.web.servlet.support.RequestContextUtils

Class Overview

Utility class for easy access to request-specific state which has been set by the DispatcherServlet.

Supports lookup of current WebApplicationContext, LocaleResolver, Locale, ThemeResolver, Theme, and MultipartResolver.

Summary

Public Constructors
RequestContextUtils()
Public Methods
static Locale getLocale(HttpServletRequest request)
Retrieves the current locale from the given request, using the LocaleResolver bound to the request by the DispatcherServlet (if available), falling back to the request's accept-header Locale.
static LocaleResolver getLocaleResolver(HttpServletRequest request)
Return the LocaleResolver that has been bound to the request by the DispatcherServlet.
static Theme getTheme(HttpServletRequest request)
Retrieves the current theme from the given request, using the ThemeResolver and ThemeSource bound to the request by the DispatcherServlet.
static ThemeResolver getThemeResolver(HttpServletRequest request)
Return the ThemeResolver that has been bound to the request by the DispatcherServlet.
static ThemeSource getThemeSource(HttpServletRequest request)
Return the ThemeSource that has been bound to the request by the DispatcherServlet.
static WebApplicationContext getWebApplicationContext(ServletRequest request, ServletContext servletContext)
Look for the WebApplicationContext associated with the DispatcherServlet that has initiated request processing, and for the global context if none was found associated with the current request.
static WebApplicationContext getWebApplicationContext(ServletRequest request)
Look for the WebApplicationContext associated with the DispatcherServlet that has initiated request processing.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public RequestContextUtils ()

Public Methods

public static Locale getLocale (HttpServletRequest request)

Retrieves the current locale from the given request, using the LocaleResolver bound to the request by the DispatcherServlet (if available), falling back to the request's accept-header Locale.

Parameters
request current HTTP request
Returns
  • the current locale, either from the LocaleResolver or from the plain request

public static LocaleResolver getLocaleResolver (HttpServletRequest request)

Return the LocaleResolver that has been bound to the request by the DispatcherServlet.

Parameters
request current HTTP request
Returns
  • the current LocaleResolver, or null if not found

public static Theme getTheme (HttpServletRequest request)

Retrieves the current theme from the given request, using the ThemeResolver and ThemeSource bound to the request by the DispatcherServlet.

Parameters
request current HTTP request
Returns
  • the current theme, or null if not found

public static ThemeResolver getThemeResolver (HttpServletRequest request)

Return the ThemeResolver that has been bound to the request by the DispatcherServlet.

Parameters
request current HTTP request
Returns
  • the current ThemeResolver, or null if not found

public static ThemeSource getThemeSource (HttpServletRequest request)

Return the ThemeSource that has been bound to the request by the DispatcherServlet.

Parameters
request current HTTP request
Returns
  • the current ThemeSource

public static WebApplicationContext getWebApplicationContext (ServletRequest request, ServletContext servletContext)

Look for the WebApplicationContext associated with the DispatcherServlet that has initiated request processing, and for the global context if none was found associated with the current request. This method is useful to allow components outside the framework, such as JSP tag handlers, to access the most specific application context available.

Parameters
request current HTTP request
servletContext current servlet context
Returns
  • the request-specific WebApplicationContext, or the global one if no request-specific context has been found
Throws
IllegalStateException if neither a servlet-specific nor a global context has been found

public static WebApplicationContext getWebApplicationContext (ServletRequest request)

Look for the WebApplicationContext associated with the DispatcherServlet that has initiated request processing.

Parameters
request current HTTP request
Returns
  • the request-specific web application context
Throws
IllegalStateException if no servlet-specific context has been found