Solved

Trapping the Browser Refresh Event in my JSP file

Posted on 2004-08-15
5
619 Views
Last Modified: 2008-02-07
hi experts,
              I am developing  a JSP page in which i need to know if the user had pressed the browser Refresh. Button.
WHy i need this is because.. I have a separate Refresh link inside my window that does some thing more than just ordinary refresh..cos i am adding a few query sting parameters and reading them.. Now i need to integrate both the refresh buttons to have the same functionality.. Now how can find that the user has pressed the Browser Refresh or not.. pls let me know..

newbie web programmer..
0
Comment
Question by:FearFactor_x
5 Comments
 
LVL 1

Accepted Solution

by:
TomBruser earned 50 total points
ID: 11804269
Your web server cannot distinguish between www.somedomain.com/someURI accessed via normal web page links or accessed via a refresh.  You will have to implement a custom solution for this:

Every URI that you want to track in this manner must be made to be unique.  You can do this by keying your CGI parameters.  i.e. instead of sending your users to http://www.blahblah.com/foo.jsp, you would send them to http://www.blahblah.com/foo.jsp?key=AB340D18AC (AB340D18AC is just a randomly generated key.  This should be unique from page hit to page hit).  When the user hits foo.jsp, read the parameter called 'key'.  Check to see if there is a session attribute named with the key.  If not, simply store a generic attribute named with the key.  If so, assume that the page refresh was used and run your 'refresh' code.

Note that this will not work effectively once the user's session has timed out.  If the user does not require a login to access these pages, as an alternate, just check to see if the session is new.  If the session is new yet the user is sending a key parameter, then the user has either bookmarked and is now revisiting one of the pages, or has hit the reload button long after the session has expired (essentially the same thing as far as your web server is concerned).  Just decide what you want to do.  Detecting this is not a problem.
0
 

Author Comment

by:FearFactor_x
ID: 11804310
the web page does not require any authentication.. So i tried to use the

if ( session.isNew () == true ) {

// Do my stuff here..


}

But the problem is that when i tried to priint  "System.out.println(session.isNew()) "; i noticed that it is always false.

1) Session.isNew() is always false for me.. even if user presses refresh
2) even if user comes back to the page thru browser back,...

Do i have to enable the sessions to use it.. Pls let me know


NewBie
0
 
LVL 3

Expert Comment

by:sbockelman
ID: 11806685
Okay, look...I realize this is going to be the worst answer you receive, but it has to be said...your problem is caused by a bad design.  There surely is some other way to meet the requirements than to be over-using one JSP for so much work.  I suggest you "step back" and rethink your design, in light of what you have learned trying to implement this one.

Your efforts thus far have not been in vain, as they have exercized one design option and helped you learn about limitations of the environment for which you are developing.

Try to think about how the application might work another way that takes these lessons into account.

Also, highly recommended, do some studying and reading about web development, and design patterns/frameworks that can make your designs more robust:

http://www.programmingtutorials.com/j2ee.aspx

http://struts.apache.org/

http://java.sun.com/reference/blueprints/index.html

http://java.sun.com/blueprints/corej2eepatterns/

Please consider my post as an attempt to help, albeit not quite a direct answer to your question.

If you think I am mistaken or misguided in offering this advice, please simply disregard my post.  I mean no disrespect.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question