Question

I'd like to know the first time a session is created in Vaadin so I can write various data that'll be kept from request to request. Some kind of application-level listener for when a session is created/destroyed. Is this possible?

-- Shane

Was it helpful?

Solution

Yes it is possible, Create a class that implements javax.servlet.http.HttpSessionListener and annotate it with @WebListener which gives you access to method sessionCreated and sessionDestroyed.

Sample Code -

@WebListener
public class UserSessionListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent arg0) {
    System.out.println("Session Created");

    }

    @Override
    public void sessionDestroyed(HttpSessionEvent arg0) {
    System.out.println("Session Destroyed");

    }

}

That is all you have to do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top