Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Stop form data load on click of refresh button  RSS feed

 
ms raaghu
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Am a novice prgrm in web apps.
I have just developed a very simple web app ..with a login page,a registration form.
Functionality:
1) Login
2) Enter all the required fields and click on submit button.
3) Data gets saved in the Db.
4) So, now, if the browser refresh button is clicked ,again the submit action is getting invoked and trying to save the record
at this a unique constraint exception is getting thrown.

How can this be avoided.Please help me out finding the solution for this.

I have thought of doing this... please let me know if this approach is valid or not?

using JavaScript to get hold of the window event and then set a flag and then proceed...
if the same can be handled at server side ..please let me know how can this be done???
 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raghu

Welcome to Javaranch

Follow these steps
1. Enter the values
2. Click on Submit
3. Enter the data to DB in servlet
4. if success/ Fail show the result in another page

in the 4th step you not doing i think. so its in the 3 step itself, if user press refresh it will call the 3rd step again. means trying to add to DB again
 
ms raaghu
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kathraj,

Thank you ... am doing the 4th step i.e. forwarding to a success page after data getting saved ... now if the user clicks on back button and clicks the refresh button the constraint error is getting triggered ..
 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can handle the exception right ?

I mean when exception is thrown, you can redirect to some other page...saying the username or whatever already exisits !
 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem mentioned in this post is similar, just check this out : -

http://www.coderanch.com/t/452944/Servlets/java/stop-submit-being-processed-twice
 
ms raaghu
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya that can be done but cant i handle in the same page without redirecting to any other page. i.e. say if refresh button is clicked then do nothing...???
 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you can do this

You need to write the javascript for clearing the history of the browser means last visited page.

This will help you

 
ms raaghu
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey chiru thanks,

but i need something which is really feasible and handled in server side ..any article or piece of code example would help me a lot..

Thanks
raghu
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"raghu ms", please check your private messages for an important administrative matter.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!