类 SessionLocaleResolver

所有已实现的接口:
LocaleContextResolver, LocaleResolver

public class SessionLocaleResolver extends AbstractLocaleContextResolver
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.

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 "Session" project. This LocaleResolver will simply evaluate and modify corresponding HttpSession attributes against the current RequestContext.

从以下版本开始:
4.0
作者:
Juergen Hoeller
另请参阅:
  • 字段详细资料

    • LOCALE_SESSION_ATTRIBUTE_NAME

      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 RequestContext(Utils).getLocale() to retrieve the current locale in controllers or views.

      另请参阅:
    • TIME_ZONE_SESSION_ATTRIBUTE_NAME

      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 RequestContext(Utils).getTimeZone() to retrieve the current time zone in controllers or views.

      另请参阅:
    • localeAttributeName

      private String localeAttributeName
    • timeZoneAttributeName

      private String timeZoneAttributeName
    • sessionManager

      @Nullable private SessionManager sessionManager
  • 构造器详细资料

    • SessionLocaleResolver

      public SessionLocaleResolver()
  • 方法详细资料