Close
« Tutorial

Spring MVC - SessionLocaleResolver MCQ

0/13
0 ✓
0 ✗

1. Where does SessionLocaleResolver store the user's selected Locale?

2. When is SessionLocaleResolver a good choice instead of the default header-based resolver?

3. How long does a locale stored by SessionLocaleResolver stay active for a user?

4. What does setDefaultLocale(..) do on a SessionLocaleResolver?

5. Which interface must a bean named localeResolver implement so that Spring MVC can use it?

6. Which method of LocaleResolver is used to change the current locale?

7. What is the job of LocaleChangeInterceptor?

8. Why is LocaleChangeInterceptor often better than setting the locale inside a controller method?

9. What kind of Spring MVC component is LocaleChangeInterceptor?

10. What does setParamName(..) configure on a LocaleChangeInterceptor?

11. What is the default request parameter name used by LocaleChangeInterceptor?

12. Which value is a valid locale text that LocaleChangeInterceptor can read from a request parameter?

13. What is the output of this code?

Locale l = Locale.GERMANY;
System.out.println(l);

14. What is the output of this code?

Locale l = Locale.FRANCE;
System.out.println(l.getLanguage());

15. A user sends a request with ?lang=de_DE. What must be changed so the locale is updated?

LocaleChangeInterceptor i =
    new LocaleChangeInterceptor();
registry.addInterceptor(i);

16. Complete the bean method so that English (US) is used when the session has no locale yet.

@Bean
public LocaleResolver localeResolver() {
    SessionLocaleResolver r =
        new SessionLocaleResolver();
    // complete here
    return r;
}

17. A user opens /home with no locale parameter. The default locale is Locale.US. Then the user sends the requests below in the same session. What locale is used for the last request?

1. GET /home
2. GET /home?locale=fr_FR
3. GET /about

18. What does a controller handler method receive when it declares a Locale parameter?

19. What will the dropdown below send to the server when the user selects German and submits?

<select name="localeCode">
  <option value="en_US">English</option>
  <option value="de_DE">German</option>
</select>

20. A config class has the code below. A user sends POST /?lang=fr_FR. What is stored in the session?

@Bean
public LocaleResolver localeResolver() {
  return new SessionLocaleResolver();
}

@Override
public void addInterceptors(
        InterceptorRegistry registry) {
  LocaleChangeInterceptor i =
      new LocaleChangeInterceptor();
  i.setParamName("lang");
  registry.addInterceptor(i);
}
Join