Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get session information in Spring MVC 3

Tags:

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

like image 905
Harry Avatar asked Sep 08 '11 03:09

Harry


People also ask

How do I find my Spring session ID?

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.

What are session attributes?

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.


1 Answers

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.

like image 86
user683887 Avatar answered Dec 08 '22 16:12

user683887