wood burning stoves 2.0*
The moose likes Servlets and the fly likes problem with page refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem with page refresh" Watch "problem with page refresh" New topic
Author

problem with page refresh

Prabhakar Rao
Ranch Hand

Joined: Aug 23, 2006
Posts: 40
I have servlet that adds a record to database and forwrds to a jsp page
when i click on refresh in IE the servlet is getting executed everytime so every time same record is adding to database creating more records

How to get rid of this
amarnath nalumachu
Greenhorn

Joined: Feb 10, 2005
Posts: 10
Query the database before you insert and if you don't find then only insert. Do you have primary key/unique key in your table? This will automatically avoid creating duplicate rows.
I have come across that session can be used to handle refresh, but I never tried.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

"prabhakar india",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Prabhakar Rao
Ranch Hand

Joined: Aug 23, 2006
Posts: 40
Thanks for that. But do not want to do it at database level. I want to have a solution with servlets methods only.
Is it possible to detect page refresh
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Read this article and pay particular attention to the "PRG technique".
 
Don't get me started about those stupid light bulbs.
 
subject: problem with page refresh
 
Similar Threads
Preventing page refresh in jsp pages
The browser's refresh button cause trouble
problem while refreshing page
refreshing problem
How to have a page CONTINUE to check Database Record?