Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trapping the Browser Refresh Event in my JSP file

Posted on 2004-08-15
5
Medium Priority
?
625 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Accepted Solution

by:
TomBruser earned 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

What monsters are hiding in your child's room? In this article I will share with you a tech horror story that could happen to anyone, along with some tips on how you can prevent it from happening to you.
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

598 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