• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The browser's refresh button cause trouble

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
I am in trouble with the refresh button now . It is like this:
I have two jsp page ,one called a.jsp ,it has a form ,and post to b.jsp.
b.jsp handles the request, and insert a record to the database,then forward back to a.jsp.At this time ,the page seems to be a.jsp ,but the address of the browser is still b.jsp .If refresh , there is one more record inserted to the database.
I think if use a servlet or struts' action to do the work which b.jsp does,the problem will appear the same.
If use redirect , I can't pass parameters. I have to display a "inserted done!" at the a.jsp if the record is inserted into the database ,or display "error" on the page and write-back the form data just inputed.

I wonder how to resolve this problem .
Thanks in advance.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, for forms that change state (like insert into a database), you should use POST, not GET. Then the browsers will at least warn you that you're about to repeat an action, and give you a chance to cancel, if you reload.

The problem is known as the DoubleSubmitProblem, and one of the ways to avoid it is the PostRedirectGet. There was an excellent article about this in the JavaRanch Journal.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic