This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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: 61106
    
  66

"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: 61106
    
  66

Read this article and pay particular attention to the "PRG technique".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with page refresh