• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with page refresh

 
Prabhakar Rao
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Prabhakar Rao
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read this article and pay particular attention to the "PRG technique".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic