org.springframework.web.servlet.LocaleResolver implementation that
uses a locale attribute in the user's session in case of a custom setting,
with a fallback to the configured default locale, the request's
Accept-Language header, or the default locale for the server.
This is most appropriate if the application needs user sessions anyway,
i.e. when the HttpSession does not have to be created just for storing
the user's locale. The session may optionally contain an associated time zone
attribute as well; alternatively, you may specify a default time zone.
Custom controllers can override the user's locale and time zone by calling
#setLocale(Context) on the resolver, e.g. responding to a locale change
request. As a more convenient alternative, consider using
org..
In contrast to CookieLocaleResolver, this strategy stores locally
chosen locale settings in the Servlet container's HttpSession. As a
consequence, those settings are just temporary for each session and therefore
lost when each session terminates.
Note that there is no direct relationship with external session management
mechanisms such as the "Spring Session" project. This LocaleResolver
will simply evaluate and modify corresponding HttpSession attributes
against the current HttpServletRequest.
setDefaultLocale, setDefaultTimeZone
| Modifier and Type | Field and Description |
|---|---|
| private Function | |
| private Function | |
| public static final String | LOCALE_SESSION_ATTRIBUTE_NAME
Default name of the session attribute that holds the Locale. |
| private String | |
| public static final String | TIME_ZONE_SESSION_ATTRIBUTE_NAME
Default name of the session attribute that holds the TimeZone. |
| private String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected Locale | Returns: the default locale (nevernull)the request to resolve the locale for request)
Deprecated
since 6.0. as of 6.0, in favor of
setDefaultLocaleFunction(Function)
Determine the default locale for the given request, called if no
|
| protected TimeZone | Returns: the default time zone (ornull if none defined)the request to resolve the time zone for request)
Deprecated
since 6.0. as of 6.0, in favor of
setDefaultTimeZoneFunction(Function)
Determine the default time zone for the given request, called if no
|
| public Locale | resolveLocale(HttpServletRequest
the request to resolve the locale for request)Overrides default org. Implements org. Default implementation of |
| public LocaleContext | resolveLocaleContext(final HttpServletRequest
the request to resolve the locale context for request)Implements org. Resolve the current locale context via the given request. |
| public void | setDefaultLocaleFunction(Function<HttpServletRequest, Locale>
the function used to determine the default locale defaultLocaleFunction)Set the function used to determine the default locale for the given request,
called if no |
| public void | setDefaultTimeZoneFunction(Function<HttpServletRequest, TimeZone>
the function used to determine the default time zone defaultTimeZoneFunction)Set the function used to determine the default time zone for the given request,
called if no |
| public void | setLocaleAttributeName(String localeAttributeName)
Specify the name of the corresponding attribute in the |
| public void | setLocaleContext(HttpServletRequest
the request to be used for locale modification request, HttpServletResponse the response to be used for locale modification response, LocaleContext the new locale context, or localeContext)null to clear the localeImplements org. Set the current locale context to the given one, potentially including a locale with associated time zone information. |
| public void | setTimeZoneAttributeName(String timeZoneAttributeName)
Specify the name of the corresponding attribute in the |
| defaultLocaleFunction | back to summary |
|---|---|
| private Function<HttpServletRequest, Locale> defaultLocaleFunction | |
| defaultTimeZoneFunction | back to summary |
|---|---|
| private Function<HttpServletRequest, TimeZone> defaultTimeZoneFunction | |
| LOCALE_SESSION_ATTRIBUTE_NAME | back to summary |
|---|---|
| public static final String LOCALE_SESSION_ATTRIBUTE_NAME Default name of the session attribute that holds the Locale. Only used internally by this implementation. Use | |
| localeAttributeName | back to summary |
|---|---|
| private String localeAttributeName | |
| TIME_ZONE_SESSION_ATTRIBUTE_NAME | back to summary |
|---|---|
| public static final String TIME_ZONE_SESSION_ATTRIBUTE_NAME Default name of the session attribute that holds the TimeZone. Only used internally by this implementation. Use | |
| timeZoneAttributeName | back to summary |
|---|---|
| private String timeZoneAttributeName | |
| SessionLocaleResolver | back to summary |
|---|---|
| public SessionLocaleResolver() | |
| determineDefaultLocale | back to summary |
|---|---|
| protected Locale determineDefaultLocale(HttpServletRequest request)
Determine the default locale for the given request, called if no
The default implementation returns the configured
default locale, if any, and otherwise
falls back to the request's
| |
| determineDefaultTimeZone | back to summary |
|---|---|
| protected TimeZone determineDefaultTimeZone(HttpServletRequest request)
Determine the default time zone for the given request, called if no
The default implementation returns the configured default time zone,
if any, or
| |
| resolveLocale | back to summary |
|---|---|
| public Locale resolveLocale(HttpServletRequest request) Overrides default org. Implements org. Doc from org. Default implementation of
| |
| resolveLocaleContext | back to summary |
|---|---|
| public LocaleContext resolveLocaleContext(final HttpServletRequest request) Implements org. Doc from org. Resolve the current locale context via the given request. This is primarily intended for framework-level processing; consider using
The returned context may be a
Custom resolver implementations may also return extra settings in the returned context, which again can be accessed through downcasting.
| |
| setDefaultLocaleFunction | back to summary |
|---|---|
| public void setDefaultLocaleFunction(Function<HttpServletRequest, Locale> defaultLocaleFunction) Set the function used to determine the default locale for the given request,
called if no The default implementation returns the configured
default locale, if any, and otherwise
falls back to the request's
| |
| setDefaultTimeZoneFunction | back to summary |
|---|---|
| public void setDefaultTimeZoneFunction(Function<HttpServletRequest, TimeZone> defaultTimeZoneFunction) Set the function used to determine the default time zone for the given request,
called if no The default implementation returns the configured default time zone,
if any, or
| |
| setLocaleAttributeName | back to summary |
|---|---|
| public void setLocaleAttributeName(String localeAttributeName) Specify the name of the corresponding attribute in the The default is an internal
| |
| setLocaleContext | back to summary |
|---|---|
| public void setLocaleContext(HttpServletRequest request, HttpServletResponse response, LocaleContext localeContext) Implements org. Doc from org. Set the current locale context to the given one, potentially including a locale with associated time zone information.
| |
| setTimeZoneAttributeName | back to summary |
|---|---|
| public void setTimeZoneAttributeName(String timeZoneAttributeName) Specify the name of the corresponding attribute in the The default is an internal
| |