Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

On reloading the jsp  RSS feed

 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • 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.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • 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.
 
Sreenivasa Majji
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • 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: 6920
  • Mark post as helpful
  • send pies
  • 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
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • 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: 1869
  • Mark post as helpful
  • send pies
  • 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: 1869
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!