类 RequestContextUtils
- java.lang.Object
- org.springframework.web.servlet.support.RequestContextUtils
public abstract class RequestContextUtils extends Object
Utility class for easy access to request-specific state which has been set by theDispatcherServlet
.Supports lookup of current WebApplicationContext, LocaleResolver, Locale, ThemeResolver, Theme, and MultipartResolver.
- 从以下版本开始:
- 03.03.2003
- 作者:
- Juergen Hoeller, Rossen Stoyanchev
- 另请参阅:
RequestContext
,DispatcherServlet
字段概要
字段 修饰符和类型 字段 说明 static String
REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
The name of the bean to use to look up in an implementation ofRequestDataValueProcessor
has been configured.
构造器概要
构造器 构造器 说明 RequestContextUtils()
方法概要
所有方法 静态方法 具体方法 已过时的方法 修饰符和类型 方法 说明 static WebApplicationContext
findWebApplicationContext(HttpServletRequest request)
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
findWebApplicationContext(HttpServletRequest 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 FlashMapManager
getFlashMapManager(HttpServletRequest request)
Return theFlashMapManager
instance to save flash attributes.static Map<String,?>
getInputFlashMap(HttpServletRequest request)
Return read-only "input" flash attributes from request before redirect.static Locale
getLocale(HttpServletRequest request)
Retrieve 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 FlashMap
getOutputFlashMap(HttpServletRequest request)
Return "output" FlashMap to save attributes for request after redirect.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 TimeZone
getTimeZone(HttpServletRequest request)
Retrieve the current time zone from the given request, using the TimeZoneAwareLocaleResolver bound to the request by the DispatcherServlet (if available), falling back to the system's default time zone.static WebApplicationContext
getWebApplicationContext(ServletRequest request)
已过时。as of Spring 4.2.1, in favor offindWebApplicationContext(HttpServletRequest)
static WebApplicationContext
getWebApplicationContext(ServletRequest request, ServletContext servletContext)
已过时。as of Spring 4.2.1, in favor offindWebApplicationContext(HttpServletRequest, ServletContext)
字段详细资料
REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
public static final String REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
The name of the bean to use to look up in an implementation ofRequestDataValueProcessor
has been configured.- 从以下版本开始:
- 4.2.1
- 另请参阅:
- 常量字段值
构造器详细资料
RequestContextUtils
public RequestContextUtils()
方法详细资料
getWebApplicationContext
@Deprecated public static WebApplicationContext getWebApplicationContext(ServletRequest request) throws IllegalStateException
已过时。as of Spring 4.2.1, in favor offindWebApplicationContext(HttpServletRequest)
Look for the WebApplicationContext associated with the DispatcherServlet that has initiated request processing.- 参数:
request
- current HTTP request- 返回:
- the request-specific web application context
- 抛出:
IllegalStateException
- if no servlet-specific context has been found- 另请参阅:
getWebApplicationContext(ServletRequest, ServletContext)
getWebApplicationContext
@Deprecated public static WebApplicationContext getWebApplicationContext(ServletRequest request, ServletContext servletContext) throws IllegalStateException
已过时。as of Spring 4.2.1, in favor offindWebApplicationContext(HttpServletRequest, 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.- 参数:
request
- current HTTP requestservletContext
- current servlet context- 返回:
- the request-specific WebApplicationContext, or the global one if no request-specific context has been found
- 抛出:
IllegalStateException
- if neither a servlet-specific nor a global context has been found- 另请参阅:
DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE
,WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContext)
findWebApplicationContext
public static WebApplicationContext findWebApplicationContext(HttpServletRequest 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. The global context will be found via the ServletContext or via ContextLoader's current context.NOTE: This variant remains compatible with Servlet 2.5, explicitly checking a given ServletContext instead of deriving it from the request.
- 参数:
request
- current HTTP requestservletContext
- current servlet context- 返回:
- the request-specific WebApplicationContext, or the global one if no request-specific context has been found, or
null
if none - 从以下版本开始:
- 4.2.1
- 另请参阅:
DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE
,WebApplicationContextUtils.getWebApplicationContext(ServletContext)
,ContextLoader.getCurrentWebApplicationContext()
findWebApplicationContext
public static WebApplicationContext findWebApplicationContext(HttpServletRequest request)
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. The global context will be found via the ServletContext or via ContextLoader's current context.NOTE: This variant requires Servlet 3.0+ and is generally recommended for forward-looking custom user code.
- 参数:
request
- current HTTP request- 返回:
- the request-specific WebApplicationContext, or the global one if no request-specific context has been found, or
null
if none - 从以下版本开始:
- 4.2.1
- 另请参阅:
findWebApplicationContext(HttpServletRequest, ServletContext)
,ServletRequest.getServletContext()
,ContextLoader.getCurrentWebApplicationContext()
getLocaleResolver
public static LocaleResolver getLocaleResolver(HttpServletRequest request)
Return the LocaleResolver that has been bound to the request by the DispatcherServlet.- 参数:
request
- current HTTP request- 返回:
- the current LocaleResolver, or
null
if not found
getLocale
public static Locale getLocale(HttpServletRequest request)
Retrieve 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.This method serves as a straightforward alternative to the standard Servlet
ServletRequest.getLocale()
method, falling back to the latter if no more specific locale has been found.Consider using
LocaleContextHolder.getLocale()
which will normally be populated with the same Locale.- 参数:
request
- current HTTP request- 返回:
- the current locale for the given request, either from the LocaleResolver or from the plain request itself
- 另请参阅:
getLocaleResolver(javax.servlet.http.HttpServletRequest)
,LocaleContextHolder.getLocale()
getTimeZone
public static TimeZone getTimeZone(HttpServletRequest request)
Retrieve the current time zone from the given request, using the TimeZoneAwareLocaleResolver bound to the request by the DispatcherServlet (if available), falling back to the system's default time zone.Note: This method returns
null
if no specific time zone can be resolved for the given request. This is in contrast togetLocale(javax.servlet.http.HttpServletRequest)
where there is always the request's accept-header locale to fall back to.Consider using
LocaleContextHolder.getTimeZone()
which will normally be populated with the same TimeZone: That method only differs in terms of its fallback to the system time zone if the LocaleResolver hasn't provided a specific time zone (instead of this method'snull
).- 参数:
request
- current HTTP request- 返回:
- the current time zone for the given request, either from the TimeZoneAwareLocaleResolver or
null
if none associated - 另请参阅:
getLocaleResolver(javax.servlet.http.HttpServletRequest)
,LocaleContextHolder.getTimeZone()
getThemeResolver
public static ThemeResolver getThemeResolver(HttpServletRequest request)
Return the ThemeResolver that has been bound to the request by the DispatcherServlet.- 参数:
request
- current HTTP request- 返回:
- the current ThemeResolver, or
null
if not found
getThemeSource
public static ThemeSource getThemeSource(HttpServletRequest request)
Return the ThemeSource that has been bound to the request by the DispatcherServlet.- 参数:
request
- current HTTP request- 返回:
- the current ThemeSource
getTheme
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.- 参数:
request
- current HTTP request- 返回:
- the current theme, or
null
if not found - 另请参阅:
getThemeResolver(javax.servlet.http.HttpServletRequest)
getInputFlashMap
public static Map<String,?> getInputFlashMap(HttpServletRequest request)
Return read-only "input" flash attributes from request before redirect.- 参数:
request
- current request- 返回:
- a read-only Map, or
null
if not found - 另请参阅:
FlashMap
getOutputFlashMap
public static FlashMap getOutputFlashMap(HttpServletRequest request)
Return "output" FlashMap to save attributes for request after redirect.- 参数:
request
- current request- 返回:
- a
FlashMap
instance, nevernull
within aDispatcherServlet
-handled request
getFlashMapManager
public static FlashMapManager getFlashMapManager(HttpServletRequest request)
Return theFlashMapManager
instance to save flash attributes.- 参数:
request
- the current request- 返回:
- a
FlashMapManager
instance, nevernull
within aDispatcherServlet
-handled request