If you have a session associated with the user, you can implement the HttpSessionBindingListener interface and get notified when the
servlet container finally times out the session and destroys it.
By using a connection pool instead of trying to manage db connections yourself, you can save a lot of trouble. You have to ensure that no matter what happens in your servlet/JSP the connection is returned to the pool manager.
Bill