Close
« Tutorial

Spring MVC - FixedLocaleResolver MCQ

0/13
0 ✓
0 ✗

1. What does FixedLocaleResolver do in Spring MVC?

2. A FixedLocaleResolver is created and no locale is set on it. Which locale does it use?

3. Besides a locale, what else can a FixedLocaleResolver optionally hold?

4. Which situation is a good reason to use FixedLocaleResolver?

5. An app uses FixedLocaleResolver with a fixed locale of Locale.FRANCE. A user sends a request with the parameter ?lang=es to switch the language to Spanish. What happens?

6. Which line should be added after creating the resolver so that it always uses the Italian locale?

FixedLocaleResolver r =
    new FixedLocaleResolver();
// add the line here
return r;

7. Which code creates a FixedLocaleResolver that is fixed to the French locale at construction time?

8. A client sends a request to / with the header Accept-Language: ja-JP. What is the response body?

@Bean
LocaleResolver localeResolver() {
    FixedLocaleResolver r =
        new FixedLocaleResolver();
    r.setDefaultLocale(Locale.GERMANY);
    return r;
}

@GetMapping("/")
@ResponseBody
String hello(Locale locale) {
    return "Locale: " + locale;
}
Join