Close
« Tutorial

Spring MVC - Client Time Zone MCQ

0/13
0 ✓
0 ✗

1. Which HTTP request header helps the server find the client's Locale?

2. Why can't the server read the client's time zone from the HTTP request headers?

3. Which Spring interface can carry time zone information together with the locale?

4. Which LocaleContext sub-interface gives access to a TimeZone?

5. Which Spring resolver classes implement LocaleContextResolver and can store 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

7. A handler method needs the time zone from the active LocaleContextResolver. Which parameter types are supported?

8. What does resolveLocaleContext() return for the time zone if none was ever set?

9. Which browser JavaScript call returns the client's time zone offset?

var d = new Date();
var offset = d._____________

10. A browser is at UTC+2. What does getTimezoneOffset() return?

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);

12. Which approach is generally better than a raw offset for finding the client's time zone in a modern browser?

13. What is the best way to send the client's time zone offset to the server?

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));

15. What is the job of this interceptor?

public boolean preHandle(
        HttpServletRequest req,
        HttpServletResponse res,
        Object handler) throws Exception {
    TimeZone tz = RequestContextUtils
            .getTimeZone(req);
    if (tz == null) {
        req.getRequestDispatcher("/getTz")
           .forward(req, res);
        return false;
    }
    return true;
}

16. A time zone interceptor forwards to /getTz and /saveTz. How should these two paths be registered so there is no endless forwarding?

registry.addInterceptor(new TzInterceptor())
        .__________________

17. How long is a client time zone remembered when SessionLocaleResolver handles it?

18. You want the client time zone to be remembered longer than one session. Which resolver should handle the time zone?

19. When is FixedLocaleResolver a good choice for time zone handling?

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);
}
Join