aspose file tools*
The moose likes JSP and the fly likes Prevent Multiple Page Refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Prevent Multiple Page Refresh" Watch "Prevent Multiple Page Refresh" New topic
Author

Prevent Multiple Page Refresh

John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
Hello all,

I have a struts web application that is giving me a problems. I recently came across a problem where if the user hit F5 multiple times it would cause an out of memory SQL exception. I found the issue and resolved the situation, however I want to ensure that this won't happen again even if something gets done incorrectly. I have been told that its possible to ignore the refresh if someone hits it multiple times in a short period. However, I can't seem to find any good documentation on how to do anything but disable the F5 button in IE and Firefox. Can someone help me with resources? Or Confirm that it simply isn't possible. I see a lot of mixed answers some indicating it is possible and then others that its not. I am under the impression that it can kind of sorta be done in certain browsers under specific situations, but nothing fool proof. Just trying to exhaust my resources before I give up on this one.
Gaurav Wadhwani
Ranch Hand

Joined: Sep 21, 2010
Posts: 68
Hi,
I dont know if it is possible to ignore refresh. But why not store a session attribute indicating no of times refreshed in a particular interval. If it exceeds threshold we can block the access. What wrong with this strategy?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

The solution is not to try and ignore F5, or any other actions, on the client. That way lies madness and frustration.

The solution is to be able to deal with it on the server. Always.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
Sorry to break this open again after a month. My first attempt was to simply decrease the number of SQL connections made to the database, but if the user hammers the refresh they can still reproduce the issue. I haven't been able to figure a good way to handle it on the client side, most of the internet seems to be struggling with resubmitting information through a form my problem comes when loading the page with information from the database. Gaurav if you had a link to some documentation that would better explain your suggestion I would appreciate it. I would like to do like Source Forge does, if you hit the refresh too many times too fast they deny you access to the server. Can that be handled by the application? Tomcat? Is that going to require a third party app?
Gaurav Wadhwani
Ranch Hand

Joined: Sep 21, 2010
Posts: 68
Why not use the counter approach. Increase it till a threshold is reached within a small interval and if so then block access.

The JSP for it would be something like this
John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
Okay so that works, I implemented something similar but instead of using a max interval I am storing a current time value then using a series of if statements to determine if my refresh cycle has expired. Seems to be working.

Thanks guys!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Prevent Multiple Page Refresh