I am new to spring MVC and I am trying to get the session information in my controller class
Right now I am using
HttpSession objHttpSession = request.getSession(true);
if I want to get session creation time and session Id I am using
objHttpSession.getCreationTime(); objHttpSession.getId();
I want to know is there any spring MVC specific way to get the session details?
Thanks in advance
currentRequestAttributes(). getSessionId(); This relies on Spring's RequestContextHolder , so it should be used with Spring MVC's DispatcherServlet or you should have a RequestContextListener declared. Also session will be created if not exists.
A session attribute is a pre-defined variable that is persistent throughout the life of a Tealeaf session. Session attributes can be used to store various data that may be referenced by events at any point during the session.
I usually declare a parameter of type HttpSession in my Spring MVC controller method when I need to access session details.
For example:
@RequestMapping("/myrequest") public void handleMyRequest(HttpSession session, ...) { ... }
I think it's the simplest way, but don't know if it fits your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With