Spring Boot - HttpSession
HttpSession
You can use HttpServletRequest.getSession()
method to get the current HttpSession.
Set Session Attribute
Use HttpSession.setAttribute()
method to set attribute to the session. The session value can be any Object.
Here is an example to set a session in the controller
1 |
|
WebUtils offers method to set Session attribute.
1 | WebUtils.setSessionAttribute(request, "foo", "bar"); |
Get Session Attribute
Use HttpSession.getAttribute()
to get attribute value
1 |
|
Get Session attribute using WebUtils:
1 | WebUtils.getSessionAttribute(request, "foo").toString(); |
Get All Session Attribute
use Enumeration e = session.getAttributeNames()
to get all the session names, then use HttpSession.getAttribute()
method to get the session attribute.
1 |
|