Solved

Trapping the Browser Refresh Event in my JSP file

Posted on 2004-08-15
5
618 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
A customer recently asked me about anti-malware and the different deployment options available for his business. Daily news about cyberattacks, zero-day vulnerabilities, and companies that suffered a security breach made him wonder if the endpoint a…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

25 Experts available now in Live!

Get 1:1 Help Now