In my first Spring-based project, I'm trying to cache my data which is created in controller by keeping it in session, just like the way I would have done in Struts' action. Then I can hopefully refer to this data from any jsp pages. For instance, I would have something like following in the my controller
And then in my jsp page, I would conventionally refer to this list as
But this code doesn't work.
If I return ModelAndView("showPage","list",list), this variable is bound to the request scope. I looked into the debugger and saw it. But I don't know how to keep this variable in the session scope.
My objective is to cache the data, so I can refer to it from any jsp pages.
Try change the scope in your applicationContext. Because by default the session scope is request and thats why your session scope was overtook by request scope.
Never try to be a hard-worker. Be a smart-worker.
Joined: Nov 19, 2002
Rajkumar balakrishnan wrote:Try change the scope in your applicationContext. Because by default the session scope is request and thats why your session scope was overtook by request scope.
Please tell me how to do this. I am just a rookie to Spring. I am having a hard time understanding and using the session scope(and others) in Spring. I wish to find some reading materials on scope usage in Spring.
I'm thinking what you need to do is add a <jsp:useBean> definition with a scope="session" to your jsp. I've not tried to do it the way you initially posted but I have used the useBean approach. The key is that the id="xx" attribute must be exactly the same as the session attribute you set in your controller.