aspose file tools*
The moose likes JSP and the fly likes repeated insert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "repeated insert " Watch "repeated insert " New topic
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: repeated insert
 
Similar Threads
Displaying Sql query string results in jsp by using Spring Framework
Struts 1.3 Database
How to construct the SQL statement ?
SQL statment into a method
auto increment a number