0

Is there a way that I can run a piece of code before a session is created. In this situation, I would like to determine whether or not a session has been created for this user or not, and if not do something, and if so, do something else.

//Sudo code.

if(session.exists){
     doSomething();
}elseP
     createSession();
     fillSessionWithValuesOnlyOnCreation();
     otherLogic();
}

The thing is, Sessions seem to be created before I can make the check to see if the session exists, I've thought aabout checking the creation time and comparing it to current time, but I was curious if there is a better and more reliable way of doing it. I'm aware of a listener that can be triggered on session creation, but I'm not sure if it will have the request info I 'll need to populate the Session. And also not sure the order of executions, and if that listener will be triggered before filters execute.

rich green
  • 1,143
  • 4
  • 13
  • 31
  • How about this http://stackoverflow.com/questions/6684451/executing-a-java-class-at-application-startup-using-spring-mvc – Jovin Thariyath Jan 22 '16 at 14:23
  • I ended up using the sessionCreated listener and adding a value pair of "new" and true. So when I go through the logic, I can just see if the session is new, if so doStuff() and set the new value to false. Thanks for the link, it may help in the future. – rich green Jan 22 '16 at 18:51

0 Answers0