Reputation: 41553
I'm using Spring MVC and I want to store request specific values somewhere so that they can be fetched throughout my request context. Say I want to set a value into the context in my Controller (or some sort of handler) and then fetch that value from some other part of the Spring request/response cycle (could be a view, view resolver, interceptor, exception handler, etc)... how would I do that?
My question is:
Does Spring MVC already provide a method to do what I described above?
If Spring doesn't have this functionality, any ideas on the best way to do this (by extending something maybe)?
Thanks!
Upvotes: 1
Views: 1842
Reputation: 4030
You could use sessionAttributes.
I took the latest version of the api (3.1) since you didn't mention your version of spring.
Upvotes: 1
Reputation: 4402
If you need to pass an object from your controller to view, you can use Spring's ModelMap.
@RequestMapping("/list")
public String list(ModelMap modelMap) {
// ... do foo
modelMap.addAttribute("greeting", "hello");
return viewName;
}
on your view:
<h1>${greeting}</h1>
Upvotes: 6