aspose file tools*
The moose likes Spring and the fly likes Keep data in session scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Keep data in session scope" Watch "Keep data in session scope" New topic
Author

Keep data in session scope

Frank Truong
Ranch Hand

Joined: Nov 19, 2002
Posts: 39
Hi,

Spring 2.5.4

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.

Please help!
Frank
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

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.
My Blog
Frank Truong
Ranch Hand

Joined: Nov 19, 2002
Posts: 39
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.

Spring is hard to learn

Thank you.
Frank
Mark Secrist
Ranch Hand

Joined: Jul 01, 2003
Posts: 89
Hi Frank,
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.

Mark

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Mark Secrist wrote:I'm thinking what you need to do is add a <jsp:useBean> definition with a scope="session" to your jsp.
Not necessary.
the key is that the id="xx" attribute must be exactly the same as the session attribute you set in your controller.

This is only appropriate for scripting variables within scriptlets.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Frank Truong wrote:<c:forEach var="elem" items${sessionScope.list} varStatus="status">

Check your syntax. Carefully.
Mark Secrist
Ranch Hand

Joined: Jul 01, 2003
Posts: 89
Bear,
Good catch. I'm fairly new to Spring and EL myself and that's how I figured out to solve this problem... just a legacy from my former JSP days.

Thanks,

Mark
Frank Truong
Ranch Hand

Joined: Nov 19, 2002
Posts: 39
Yes. I saw my typo. But it was too late after I hit the 'Submit' button. I should have cut and pasted my code, instead! Otherwise, modern IDEs would have complained about it. I'm not using Notepad...

But that was where my bumper was.

Thanks, all.
Frank

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Keep data in session scope