My action is inserting data from form into the database. Now my problem is every time, user hits "refresh" button of browser, the action class is called with existing data and fresh new entry with the same database is made. Is there any way to get refresh just refresh the data rather than calling the action class? or at the minimum prevent 'refresh' on the page?
Is there any way to get refresh just refresh the data rather than calling the action class? or at the minimum prevent 'refresh' on the page?
No. The "Refresh" functionality of the Internet Explorer Web browser cannot be altered or suppressed.
To handle your problem, you need to code the application to not insert identical data into the database. So, if user hits refresh, the application will not process the same data twice.
Alternatively, you can try and fiddle with the page cache of the browser. But, take note that there is no guaranteed method and you'll find conflicting information on how to not cache a page in a specific browser.
I'd suggest that you code two different actions: One that performs the database update, and another that prepares the JSP for display. Then create a forward to the second action from the first, specifying redirect="true". Example:
If you do this, the user can press refresh all he wants and all that will happen will be for the display action to be called, not the update action. [ July 02, 2008: Message edited by: Merrill Higginson ]