| Author |
repeated insert
|
manu chaox
Ranch Hand
Joined: Apr 10, 2006
Posts: 110
|
|
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
Joined: Dec 11, 2004
Posts: 13410
|
|
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.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
 |
|
|
subject: repeated insert
|
|
|