This can be done by using a HttpSessionListener. You can have your Java Program implement this interface. The sessionDestroyed() method here is invoked when the session expires. So you can put the required statements in this method.