Close
« Tutorial

Spring MVC - @RequestHeader MCQ

0/13
0 ✓
0 ✗

1. What is the main purpose of the @RequestHeader annotation in Spring MVC?

2. Which element of @RequestHeader is used to specify the name of the HTTP header to bind?

3. What is the default value of the required element in @RequestHeader?

4. If a required request header is missing and required is left at its default, what HTTP status code is returned?

5. What does setting required = false on @RequestHeader do?

6. What is the effect of specifying a defaultValue in @RequestHeader?

7. When can the value element of @RequestHeader be omitted?

8. Which parameter type can be used with @RequestHeader to receive all request headers as a map?

9. Which Spring-specific type can be used with @RequestHeader to access all headers and convenience methods like getContentType()?

10. Can a single controller method have multiple @RequestHeader annotations?

11. What happens if two handler methods have the same URI mapping but rely on different @RequestHeader parameters without specifying headers in @RequestMapping?

12. How can ambiguity between handler methods that differ only by request headers be resolved?

13. If the target method parameter is not String, what does Spring MVC do with the header value?

14. Which annotation is used to read a request header named User-Agent into a method parameter?

public String handle(@_____("User-Agent") String userAgent) { ... }

15. Which annotation element should be used to make a request header optional?

@RequestHeader(value = "Accept", _____ = false) String acceptHeader

16. Which annotation element provides a fallback value when the header is missing?

@RequestHeader(value = "Accept", _____ = "application/json") String acceptHeader

17. Which parameter type collects all request headers into a single object?

public String handle(@RequestHeader _____ headers) { ... }

18. What is the relationship between the value and name elements of @RequestHeader?

19. Which element of @RequestHeader was added in Spring 4.2 as an alias for value?

20. If a header value is an empty string and a defaultValue is specified, which value is used?

Join