• 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

On reloading the jsp

 
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
On making a submit operation from jsp if i refresh
the page by using right-click "reload" it it again performing it and hence multiple insert.
Can it be avoided without putting any check on db ? what can be consequences or compromises one have to face for that?
Thanks
Varun.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sure I have covered this recently in another thread, but here it is again.
My favourite solution for this problem is to add a hidden field to the form which has some sort of unique "sequence number", different each time the form is used, generated at the time the HTML for the form is generated. In the code for processing the form, keep track of whether each "sequence number" has been processed yet. If you see one of them again, ignore it - it's a re-send.
It may be that your form already has such a field (invoice number, fault id, whatever ...), if so, you can just use that without any extra hidden fields.
 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or you can keep a flag in a cookie and check that before inserting into the database.
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or you can keep a flag in a cookie and check that before inserting into the database.
The trouble with using cookies directly is that what browsers do with cookies when then a user has multiple browser windows open is a bit of a "grey area" in the standard. Some browsers have separate cookies for each window, some share cookies between all windows, some copy cookies when a new window is opened etc.
I can easily imagine a situation where I have two browser windows open stepping through the same sequence of pages and forms. I would find it extremely irritating if I was not able to submit a form in window 1 because I have already submitted it in window 2
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Varun ,
Another strategy is as follows
Form SUBMIT --- > response.sendredirect() Page putting parameters in session or in the url--> Sucess Page.

Here if in the success page if the user clicks on refresh he gets the success page without any database update.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
However in this Case the user needs to click back twice to go to the Form page again to enter new data.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh one more thing
This strategy is similar to one used on Javaranch when you add a reply ore create a new topic you will see a page that says that you are being forwarded.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic