I am writing an app for multiple users and I need to lock/unlock records while users are updating information. My problem is with unlocking because a user can just close the browser and forget to unlock the record. I tried using the unload event as shown below but it doesn't work.
The alert box will display but then nothing happens and it never goes back to the servlet. Any help would be greatly appreciated. Thanks, Ezra
posted 14 years ago
This is the most commonly asked question in this entire forum. Do a search and you'll find it answered many times. The answer is you can't. There's no way to communiate to the server when they close the browser. The closest you can come is to use the HttpSessionBindingListener interface so that when the user's session times out it closes your files, or unlocks your records, or whatever. By the way, I would consider any implementation that locks records between HTTP calls to be HIGHLY suspect. You really shouldn't do that! Try using optimistic concurrency (timestamps) instead of pessimistic concurrency. Your life will be much easier in the long run. Kyle