1. What is the modern and recommended way to pass data to a redirect target in Spring MVC?
Why: RedirectAttributes is the explicit and recommended way to pass data for a redirect.
2. Which package contains the RedirectAttributes interface?
Why: RedirectAttributes is part of the org.springframework.web.servlet.mvc.support package.
3. Which method is used to add an attribute to RedirectAttributes?
Why: addAttribute adds an attribute that will be available in the redirect request.
4. When a redirect URL contains URI template variables, what happens to a RedirectAttributes attribute whose name matches a variable?
Why: Attributes that match URI template variables are used to fill those variables in the redirect path.
5. What happens to a RedirectAttributes attribute that does not match any URI template variable in the redirect URL?
Why: Attributes that do not match URI template variables are appended to the redirect URL as query parameters.
6. In the code below, what does ra.addAttribute("name", "John") do?
public String handle(RedirectAttributes ra) {
ra.addAttribute("name", "John");
return "redirect:/greeting";
}
Why: addAttribute passes data to the redirect target so it can be used in the redirected request.
7. After a redirect, how can data added with RedirectAttributes usually be accessed in the target handler?
Why: Data added with RedirectAttributes appears in the redirect request and can be read as request parameters or path variables.
8. What does setContextRelative(true) do when used with RedirectView?
Why: When set to true, a redirect URL starting with a slash is resolved relative to the current servlet context.
9. What is the effect of using the redirect: prefix in a return value such as return "redirect:/target";?
Why: The redirect: prefix tells Spring MVC to perform a redirect instead of resolving a normal view name.
10. When a redirect URL has both URI template variables and query parameters, how are RedirectAttributes handled?
Why: Spring first uses matching attributes for URI template variables, then adds the remaining attributes as query parameters.
11. Which statement about RedirectAttributes is correct?
Why: RedirectAttributes extends Model and is designed for attributes used in a redirect scenario.
12. What is a main benefit of using RedirectAttributes instead of adding data directly to a normal Model for a redirect?
Why: RedirectAttributes makes the intent clear: the attributes are specifically for a redirect.