Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

repeated insert

 
manu chaox
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a following problem. I have a JSP page which call java function first.

JSP:


AClass.java:


All works fine. But if I refresh page, a row will be inserted in database again.

Can I prevent repeated insert?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a general rule, you should avoid any database operations that change the state of your DB or app on requests of type GET.

With requests of type POST, the browsers will help you a bit by either using a cached version of the page, if available, or by warning the user that refreshing this page (or going to it with the back button) will cause the post that generated it to be repeated.

If it's too late for that, you could try putting a marker in session scope when the user first access this page. Then check for the marker before performing your database insert.



That would, at least limit inserts to one per user session.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic