Its probably worth nothing that if a user like me turned up on your site and saw this behaviour, I'd never be back. Sites that alter normal browser behaviour are nasty.
You also probably need to be aware that it is not 100% possible to do this. If I turned up on your site with my default browser (FireFox running no-script) there is no way of preventing me navigating back.
Is your program going to run on the web or for a set of users.
In all my previous projects, we have faced this issue and we have resolved this by patching the browser and remove the back and forward buttons altogether. The users didn't have admin rights and hence could not enable the buttons.
If the project is supposed to run on the web, then better display a message like "Please don't press back or Refresh button" as we see on the payment gateways.
Or you can set a hidden field in HTML and based on its value, invalidate the session if using JSP/Servlets.
One more application on which I worked, the custom server was written which could easily detect if the back or forward buttons have been presed using the hidden variable. I mean server automatically added hidden field in every HTML page that it sent so that the developers needn't worry about this issue.