User's session

Hello.
I have following situation: i need to create new folder on server for every new user’s session and delete it after end of session. How can i do that?

P.S. Sorry for my bad English.

Hello Bulat,

You should use a weblistner to achieve this - pls have a look at javax.servlet.http.HttpSessionListener This interface has two method sessionCreated() and sessionDestroyed() both of these would be invoked whenever the session is created and destroyed respectively.

@WebListener
public class UserSessionListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent arg0) {
    //TODO create a folder

    }

    @Override
    public void sessionDestroyed(HttpSessionEvent arg0) {
    //TODO delete the folder associated with this user

    }

}

Jus in case if you are not using servlet 3.0 API and using web.xml then add the following in your web.xml and dont use the annotation @WebListener on you user session listener class

<listener> <listener-class>***Your Custom User session listener Class with full path***</listener-class> </listener> Hope this helps you. Pls let me know incase of any futher issues.

Thanks,
Krishna.

I have another question: can session be expired while ui is still running?

Session will not be expired if there is an interaction on the UI by the user. Having said that, in case, the UI is idle for some time and the param
closeIdleSession
is set to
true
then the session would expire based on values configured for param
session-timeout
. in case if
closeIdleSession
is
false
the session would never expire and has to be invalidated in your source!

Hi, in my project i need to close session only if UI is close and there is no requests from client during some time. How can i do that? And how can i check if closeIdleSession is true or not?

You mean to say that on close of Browser you wish to close the session? If so there are two options

  1. Check for Browser window close listener. As far as I know, need to check, this is currently not possible directly in Vaadin
  2. When ever Browser window is closed, after some time session gets expired as there are no requests from the client.

And for your other question,
closeIdleSession
is set web.xml. Please have look at
this
link.

Thanks,
Krishna.

Hello again. Now i have a problem that i get Session Expired message when i’m opening my application’s web page.

And there is a problem that i cant upload my log file here for some reason

http://rghost.ru/private/56292993/177c768973379e127cc093e2c58fffae
Here is my log.

Hello Bulat,

Your logs speaks everything,

java.lang.UnsupportedClassVersionError: eei/ui/UserSessionListener : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)

It seems that there is a mismatch between compile version of java and runtime version of java. May be you compiled the soruce on JDK 1.7 and trying to run the same on Java 1.6. Please check your environment.

Thanks,
Krishna