Top Description Methods
org.springframework.web.servlet

public Interface LocaleResolver

Known Direct Subinterfaces
org.springframework.web.servlet.LocaleContextResolver
Known Direct Implementers
org.springframework.web.servlet.i18n.AbstractLocaleResolver
Imports
java.util.Locale, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.springframework.lang.Nullable

Interface for web-based locale resolution strategies that allows for both locale resolution via the request and locale modification via request and response.

This interface allows for implementations based on request, session, cookies, etc. The default implementation is org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver, simply using the request's locale provided by the respective HTTP header.

Use org.springframework.web.servlet.support.RequestContext#getLocale() to retrieve the current locale in controllers or views, independent of the actual resolution strategy.

Note

As of Spring 4.0, there is an extended strategy interface called LocaleContextResolver, allowing for resolution of a org.springframework.context.i18n.LocaleContext object, potentially including associated time zone information. Spring's provided resolver implementations implement the extended LocaleContextResolver interface wherever appropriate.

Author
Juergen Hoeller
Since
27.02.2003
See Also
LocaleContextResolver, org.springframework.context.i18n.LocaleContextHolder, org.springframework.web.servlet.support.RequestContext#getLocale, org.springframework.web.servlet.support.RequestContextUtils#getLocale

Method Summary

Modifier and TypeMethod and Description
public Locale

Returns:

the current locale (never null)
resolveLocale
(HttpServletRequest
the request to resolve the locale for
request
)

Resolve the current locale via the given request.

public void
setLocale(HttpServletRequest
the request to be used for locale modification
request
,
HttpServletResponse
the response to be used for locale modification
response
,
Locale
the new locale, or null to clear the locale
locale
)

Set the current locale to the given one.

Method Detail

resolveLocaleback to summary
public Locale resolveLocale(HttpServletRequest request)

Resolve the current locale via the given request.

Can return a default locale as fallback in any case.

Parameters
request:HttpServletRequest

the request to resolve the locale for

Returns:Locale

the current locale (never null)

setLocaleback to summary
public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale)

Set the current locale to the given one.

Parameters
request:HttpServletRequest

the request to be used for locale modification

response:HttpServletResponse

the response to be used for locale modification

locale:Locale

the new locale, or null to clear the locale

Exceptions
UnsupportedOperationException:
if the LocaleResolver implementation does not support dynamic changing of the locale