1. What is the purpose of the @SessionAttribute annotation?
Why: @SessionAttribute is used to bind a pre-existing session attribute to a parameter of a handler method.
2. Since which Spring version is @SessionAttribute available?
Why: @SessionAttribute was introduced in Spring 4.3.
3. Where can the @SessionAttribute annotation be placed?
Why: @SessionAttribute targets method parameters only. It is used on handler method parameters.
4. What is one benefit of using @SessionAttribute instead of using HttpSession directly?
Why: With @SessionAttribute, Spring can convert the value to the parameter type and check if the attribute is required.
5. What is the default value of the required element in @SessionAttribute?
Why: The required element is true by default, so the session attribute must exist.
6. What happens if the session attribute is missing and required is true?
Why: When the attribute is not in the session and required is true, Spring throws an exception.
7. What happens if the session attribute is missing and required is set to false?
Why: With required = false, Spring does not throw an exception. The parameter value can be null.
8. Which element of @SessionAttribute is used to give the name of the session attribute?
Why: The name element sets the session attribute name. The value element is an alias of name.
9. What is the relationship between the value and name elements of @SessionAttribute?
Why: value and name are aliases. You can use either one to specify the session attribute name.
10. Which statement about @SessionAttributes (with an s) is correct?
Why: @SessionAttributes is limited to a local controller and works with model attributes. It is a different annotation from @SessionAttribute.
11. Which kind of session attributes is @SessionAttribute designed for?
Why: @SessionAttribute is for pre-existing session attributes that are managed globally, for example by a filter or an interceptor.
12. Which of these is a good place to put an attribute into the session before a controller reads it with @SessionAttribute?
Why: Filters and interceptors can add attributes to the session before the controller runs. The controller can then read them with @SessionAttribute.
13. Which use case is best suited for @SessionAttribute?
Why: @SessionAttribute suits cases like reading user authentication information that was stored in the session earlier.
14. Which use case is best suited for @SessionAttributes (with an s) rather than @SessionAttribute?
Why: @SessionAttributes fits workflows limited to one controller, such as form validation and submission.
15. What does it mean that @SessionAttribute works with a pre-existing session attribute?
Why: @SessionAttribute only reads an attribute that already exists in the session. It does not create the attribute.