Class AcceptHeaderLocaleResolver
java.lang.Object
org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
- All Implemented Interfaces:
- LocaleResolver
LocaleResolver implementation that simply uses the primary locale
 specified in the "accept-language" header of the HTTP request (that is,
 the locale sent by the client browser, normally that of the client's OS).
 Note: Does not support setLocale, since the accept header
 can only be changed through changing the client's locale settings.
- Since:
- 27.02.2003
- Author:
- Juergen Hoeller, Rossen Stoyanchev
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionThe configured default locale, if any.Return the configured list of supported locales.resolveLocale(HttpServletRequest request) Resolve the current locale via the given request.voidsetDefaultLocale(Locale defaultLocale) Configure a fixed default locale to fall back on if the request does not have an "Accept-Language" header.voidsetLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) Set the current locale to the given one.voidsetSupportedLocales(List<Locale> locales) Configure supported locales to check against the requested locales determined viaServletRequest.getLocales().
- 
Constructor Details- 
AcceptHeaderLocaleResolverpublic AcceptHeaderLocaleResolver()
 
- 
- 
Method Details- 
setSupportedLocalesConfigure supported locales to check against the requested locales determined viaServletRequest.getLocales(). If this is not configured thenServletRequest.getLocale()is used instead.- Parameters:
- locales- the supported locales
- Since:
- 4.3
 
- 
getSupportedLocalesReturn the configured list of supported locales.- Since:
- 4.3
 
- 
setDefaultLocaleConfigure a fixed default locale to fall back on if the request does not have an "Accept-Language" header.By default this is not set in which case when there is no "Accept-Language" header, the default locale for the server is used as defined in ServletRequest.getLocale().- Parameters:
- defaultLocale- the default locale to use
- Since:
- 4.3
 
- 
getDefaultLocaleThe configured default locale, if any.This method may be overridden in subclasses. - Since:
- 4.3
 
- 
resolveLocaleDescription copied from interface:LocaleResolverResolve the current locale via the given request. Can return a default locale as fallback in any case.- Specified by:
- resolveLocalein interface- LocaleResolver
- Parameters:
- request- the request to resolve the locale for
- Returns:
- the current locale (never null)
 
- 
setLocalepublic void setLocale(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable Locale locale) Description copied from interface:LocaleResolverSet the current locale to the given one.- Specified by:
- setLocalein interface- LocaleResolver
- Parameters:
- request- the request to be used for locale modification
- response- the response to be used for locale modification
- locale- the new locale, or- nullto clear the locale
 
 
-