How to avoid duplicate when a user click the “refresh” button of his browser?

StackOverflow https://stackoverflow.com/questions/16581525

  •  29-05-2022
  •  | 
  •  

Question

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?

Was it helpful?

Solution

You have to use saveToken() method in action class and reset token values. which is available in Struts

OTHER TIPS

You can use struts tokens- Prevent Duplicate Submission

http://www.techfaq360.com/tutorial/multiclick.jsp

and Always check for duplicate in database

I'm not sure if this is what you're looking for but see if serves as a starting point: http://www.whoopis.com/howtos/jscript-refresh-save.php

As for the database entry problem, that should be taken care by your primary key of the database. If there's a pre-existing value for the same primary key, you shouldn't update!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top