I have two controllers, say controllerA and controllerB. ControllerA has a consultation object that I need to send to a consultation jsp. I’m using return forward: consultation.
However, after I reach the jsp, I need the consultation object both for that jsp and to use in another controller, if the user presses a confirm button.
I tried @SessionAttributes and found it’s only available for the first controllerA. Then I tried using flashAttributes, but I wasn’t able to verify if the redirect worked as the form in the jsp needs to be blank the first time it loads and it threw an error: Expected session attribute ‘consultation’.
redirectAttrs.addFlashAttribute("AttributeName", value);
return "redirect:consultation";
I ended up with using HttpSession as a workaround. So in this situation, is that the proper way to do this or did I just not set this up right?
Apparently this is the correct way to do this in my case.
I put the object in the session and when the user is on the jsp page, the controller is fired from a submit button. Then everything I need is in the session and I retrieve it.