• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there a way to control Refresh click

 
Suren Raj
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
is there a way to control refresh click of the windows on a jsp file ? I dont want to disable it.
The problem i faced is, whenever i do refresh (right-click and selected refresh or refresh from main menu) my JSP file submits the servlet with the last selected handle or button. Instead i would prefer having my own handle or prefrences.
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am thinking javascript is the best way to go for this.
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a J2EE pattern for that - you have some token on a page and in a session, and each request you compare them - works pretty fine to me.
JavaScript can not really detect a reload until page is reloaded. Onunload event does not really helps with that.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Yuriy Fuksenko but still not completely.
My preferred solution if you are just protecting them from re-sumbitting data is to use sendRedirect to connect the pages rather than include or forward.
ie client submits page, page is processed, sendRedirect is sent to client, forcing the client to re-request the page.
This way a reload sends another request for the page rather than another re-submitting the data. It should be used sparingly since it involves two HTTP calls rather than one, but in practice it isn't too bad.
Dave
 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David u are right.

But in the case where we are forced to use forward
or include then how do we maintain.
Yuriy can u please give me a pattern name or link
for avoiding of inserting new data in the database
while page refresh.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Jignesh",
We are light on rules at the JavaRanch, but the Naming Policy is one that we enforce.
You need to edit your display name soon or your account will be deleted!
Thanks,
Dave
 
Vikalp Singh
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can do this by one more way,
by disabling the control button by javascript and opening the browser with no header.
 
senthil sen
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone send a code for this solution?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!