Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Workaround for browser refresh/back button clicks?

 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp from where I do database add operation using HTML forms.
The request goes to a servlet, ejb and comes back with attributes..
Depending on the attribute values, I display alerts in the jsp.
I have the attribute checking and alert display code inside a page load function.
So the problem is when the browser refresh or back buttons are clicked, the alerts show up.
I don't like it that way..
Is there a way to check and bypass browser button click events??
Please help..
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What don't you like about this?

If the user refreshes the page, the problem doesn't go away.
Don't you want the error message to persist until the user fixes the problem or moves on to another page?
 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine if the form is empty and user hits refresh, the alert still shows up..
Also there could be many options such as Add, update, delete in the jsp..
When refresh is clicked, alerts may be displayed at random..
I think that's wrong..Does that make sense?
How about the back button? It should not display anything anyway for browser back button event.. Should it?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, using alerts for error messages is about as 1995 as you can get. Rather, use conditionals in the server side code to show the error message(s) directly on the page.

Secondly, you should not try to solve problems with your application by trying to hobble the user's browser. Not only can you usually not do it gracefully, or at all, it's just bad user interface design.

If you want to show the error messages once and only once, you could do something like store the messages in the session, and once they are displayed on the page the first time, remove them. A subsequent refresh of the page will find no messages to display.
 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain me better with some examples for
(i) conditionals in the server side code
&(ii) store the messages in the session and remove them after first time display
 
Giovanni Orso
Greenhorn
Posts: 4
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic