1. Which HTTP request header helps the server find the client's Locale?
Why: The browser sends Accept-Language automatically, so the server can find the client's locale from it.
2. Why can't the server read the client's time zone from the HTTP request headers?
Why: HTTP has no standard header for the client's time zone. The client must send this information in another way, for example as a request parameter.
3. Which Spring interface can carry time zone information together with the locale?
Why:LocaleContextResolver extends LocaleResolver. It can resolve and set a LocaleContext that includes a time zone.
4. Which LocaleContext sub-interface gives access to a TimeZone?
Why:TimeZoneAwareLocaleContext adds the method getTimeZone() to LocaleContext.
5. Which Spring resolver classes implement LocaleContextResolver and can store a time zone?
Why: Spring provides three implementations: session based, cookie based and fixed. Any of them can hold a time zone.
6. A client is in New York and the server is in Tokyo. What does the handler print?
@RequestMapping("/test")
public void show(ZoneId zid) {
System.out.println(zid);
}
// No time zone was set
// in LocaleContextResolver
Why: When no time zone is set, Spring fills TimeZone and ZoneId handler parameters with the system default. The client's time zone is not detected automatically.
7. A handler method needs the time zone from the active LocaleContextResolver. Which parameter types are supported?
Why: Handler methods can declare TimeZone or ZoneId parameters. Spring fills them from the active resolver.
8. What does resolveLocaleContext() return for the time zone if none was ever set?
Why: The system default fallback only applies to handler method parameters. Reading the time zone directly from the resolved context gives null unless it was set earlier.
9. Which browser JavaScript call returns the client's time zone offset?
var d = new Date();
var offset = d._____________
Why:Date#getTimezoneOffset() returns the difference between UTC and local time in minutes.
10. A browser is at UTC+2. What does getTimezoneOffset() return?
Why:getTimezoneOffset() returns minutes behind UTC. For a zone ahead of UTC by 2 hours, the value is negative: -120.
11. The browser sends the value getTimezoneOffset() returned. How should the server turn it into a ZoneOffset?
int offset = 300;
ZoneOffset zo = ZoneOffset
.ofTotalSeconds(________);
System.out.println(zo);
Why: The JavaScript offset is in minutes and has the opposite sign of a normal UTC offset. So multiply by 60 for seconds and negate it. For 300 this gives -05:00.
12. Which approach is generally better than a raw offset for finding the client's time zone in a modern browser?
Why:Intl.DateTimeFormat().resolvedOptions().timeZone returns a real zone id like America/Chicago. A raw offset has no daylight saving rules and cannot tell zones with the same offset apart.
13. What is the best way to send the client's time zone offset to the server?
Why: The server cannot know the time zone by itself. JavaScript reads it in the browser and sends it, for example as a hidden form field.
14. How does a controller use LocaleContextResolver to apply the time zone received from the client?
LocaleContextResolver r = ...;
r.________(req, res, new SimpleTimeZoneAwareLocaleContext(
locale, tz));
Why:setLocaleContext() stores a locale context that can include a time zone. SimpleTimeZoneAwareLocaleContext is a ready-made implementation.
Why: When no time zone is known, the interceptor forwards the request to a page that collects it from the client. Returning false stops normal handling. When a time zone exists, the request continues.
16. A time zone interceptor forwards to /getTz and /saveTz. How should these two paths be registered so there is no endless forwarding?
Why: The interceptor must not run for the paths that collect and save the time zone. Without the exclusion, these requests would be forwarded again and again.
17. How long is a client time zone remembered when SessionLocaleResolver handles it?
Why:SessionLocaleResolver keeps the time zone in the HTTP session, so it is remembered only for the session lifetime.
18. You want the client time zone to be remembered longer than one session. Which resolver should handle the time zone?
Why:CookieLocaleResolver stores the value in a cookie, so it can live longer than the session.
19. When is FixedLocaleResolver a good choice for time zone handling?
Why:FixedLocaleResolver uses one fixed time zone for everyone. No JavaScript or redirect interceptor is needed.
20. In a composite resolver, locale work goes to one resolver and time zone work goes to another. What does the composite look like?
public Locale resolveLocale(
HttpServletRequest req) {
return localeResolver
.resolveLocale(req);
}
public LocaleContext resolveLocaleContext(
HttpServletRequest req) {
return tzResolver
.resolveLocaleContext(req);
}
Why: A composite resolver can use one strategy for the locale and a different one for the time zone. Each method delegates to the resolver that handles that part.