I am using a JSP page to submit data for insert into a database.
If the refresh button (in the browser IE5) is clicked, the data is resent and inserted into the database again. How can this be prevented?
Luigi Viggiano I usually avoid this problem separating "view" pages from "controllers". The form is displayed in a "view" page that submit data to the controller, then the controller forwards to a result page (that can be another view). In this way, the page displayed on the client doesn't do anything else than displaying something, and refreshing doesn't give any problem.
____________________ | | (sometime can | View (with a form) | be implemented |____________________| with plain html) | | (submit data) | _________V__________ | | | Controller | (can be | (handles data | a "mute" JSP | manipulation and | or a servlet | persistence ) | that doesn't |____________________| give any output) | | (forward) | _________V__________ | | (can be a JSP | View (result page) | displaying | with eventually | inserted data) | another form | |____________________|So, refreshing a "view" page doesn't imply any submit or any data storage, because views are incharged just to "display" something, and controllers cannot be refreshed by the client because they are invisible to him. Sometimes view can be implemented just with plain html without using JSP