You might be able to use JavaScript to send some request back to the server upon closing the browser window. I don't know for sure.
I do know that this is not a Java in General (beginners) type question.
If you're looking for a better understanding of how sessions are handled in Java-based web applications, I recommend moseying on over to the Servlets forum.
I'm moving this thread to the HTML and JavaScript forum...