Reputation: 2642
I am using Spring Framework. Well in some part of program I store an Attribute in session like this
req.setAttribute("learnerGroup", form.getGroup(), WebRequest.SCOPE_SESSION); // save the object/String in session
Where req
is of type - WebRequest
.
In the other part of program I have HttpServletRequest hreq
.
Questions
1) Is it right way to save Object
s is session, like I did above using WebRequest
?
2) How do I retrieve the saved Object
from the session using HttpServletRequest
?
Upvotes: 3
Views: 3488
Reputation: 335
session object attributes are final, so you may not be able to update them.
But you can try this: perform getAttribute()
, save it somewhere and setAttribute()
.
Sessions are not subjected to change or update, they are meant to be created and invalidated. Maybe that is the reason, we do not have update Attribute there.
Upvotes: 0
Reputation: 691635
Yes, that will indeed save the object in the session attribute named "learnerGroup"
.
using request.getSession().getAttribute("learnerGroup")
Upvotes: 4