Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get and set attributes in session - Spring framework

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 Objects is session, like I did above using WebRequest ?

2) How do I retrieve the saved Object from the session using HttpServletRequest ?

like image 898
Junaid Avatar asked Apr 10 '26 16:04

Junaid


1 Answers

  1. Yes, that will indeed save the object in the session attribute named "learnerGroup".

  2. using request.getSession().getAttribute("learnerGroup")

like image 52
JB Nizet Avatar answered Apr 13 '26 05:04

JB Nizet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!