aspose file tools*
The moose likes JSP and the fly likes Workaround for browser refresh/back button clicks? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Workaround for browser refresh/back button clicks?" Watch "Workaround for browser refresh/back button clicks?" New topic
Author

Workaround for browser refresh/back button clicks?

Steve Renard
Ranch Hand

Joined: Apr 27, 2007
Posts: 66
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

Joined: Dec 11, 2004
Posts: 13410

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?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Steve Renard
Ranch Hand

Joined: Apr 27, 2007
Posts: 66
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

Joined: Jan 10, 2002
Posts: 61766
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Renard
Ranch Hand

Joined: Apr 27, 2007
Posts: 66
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

Joined: Jul 06, 2007
Posts: 4
struts ActionMessagge for example

http://struts.apache.org/1.2.7/api/org/apache/struts/action/ActionMessage.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Workaround for browser refresh/back button clicks?