开发者

Passing ModelAttribute across multiple requests in Spring MVC

开发者 https://www.devze.com 2023-04-10 13:32 出处:网络
I have a multiple criteria search form with a command attribute. On the first submit, 开发者_StackOverflowresults are obtained based on the options in command object. On the results page, there is a l

I have a multiple criteria search form with a command attribute. On the first submit, 开发者_StackOverflowresults are obtained based on the options in command object. On the results page, there is a link to export all the results to excel.. I have implemented it using the XMLViewResolver. I need to pass the SearchForm model attribute to the controller that handles this export requests. Also, from search results page, user can click on a person's profile and can come back to search results again. I want to keep this Model Attributes in session across all these requests. How would I achieve that in Spring MVC? @SessionAttributes is probably not an option because, as I understand, once the request goes to different controller, this object is flushed.


You can store whatever object you would like (SearchForm model) in the session associated with the HttpRequest via request.getSession();

This will allow you to access your model from the session within all controllers.

You could also store the criteria as hidden form fields on the form responsible for the user action. For instance, when the user clicks export to excel, the button would be contained within a form which contains hidden form fields whose values are set from the previous SearchForm bean.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号