Solved

Trapping the Browser Refresh Event in my JSP file

Posted on 2004-08-15
5
617 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
Veeam Backup & Replication has added a new integration – Veeam Backup for Microsoft Office 365.  In this blog, we will discuss how you can benefit from Office 365 email backup with the Veeam’s new product and try to shed some light on the needs and …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now