Reputation: 97
I am using spring security in my application.
In one of my controller method I am redirecting to another controller method and attaching model Attributes but I am not getting those modelAttributes in next controller method.
Is it happening because of some internal redirection from Spring Security Filter which might be killing those redirect flash attributes?
This is my code :
@RequestMapping("/method1")
public String firstMethod(Model model,RedirectAttributes redirectAttributes) {
... do something ...
redirectAttributes.addFlashAttributes("message","This is a test message");
return "redirect:/method2";
}
@RequestMapping("/method2")
public String secondMethod(@ModelAttribute("message") String message, Model model) {
... do something ...
return "some_view";
}
Here in secondMethod message is coming as blank( "" );
Upvotes: 2
Views: 1730
Reputation: 722
If you use redirect it wont carry headers or attribites.But You can maintain the session and you can use it if it's in same application.Using redirect means creating new request.
You better use Custom falsh scope
Upvotes: 0
Reputation: 2774
Use addAttribute
instead of addFlashAttributes
Read the difference here
@RequestMapping("/method1")
public String firstMethod(Model model,RedirectAttributes redirectAttributes) {
redirectAttributes.addAttribute("message","This is a test message");
return "redirect:/method2";
}
@RequestMapping("/method2")
public String secondMethod(@ModelAttribute("message") String message, Model model) {
return "some_view";
}
Upvotes: 1