Configuring CookieLocaleResolver

We use CookieLocaleResolver in the following example:

    <bean id="localeResolver" 
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">

<property name="defaultLocale" value="en" />
<property name="cookieName" value="userLocaleCookie"/>
<property name="cookieMaxAge" value="7200"/>

</bean>

The following definitions explain the workings of the preceding code block:

  • <property name="cookieName" value="userLocaleCookie"/>: The name of the cookie stored in the browser is userLocaleCookie.
  • <property name="cookieMaxAge" value="7200"/>: The lifetime of the cookie is 2 hours (7200 seconds).
  • Since we are using LocaleChangeInterceptor from the previous example, if you append language=en to any URL, you would be using the en locale for a duration of 2 hours (or until the locale is changed). If you append language=fr to any URL, then you would be using a French locale for 2 hours (or until the locale is changed).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset