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
Solved

Trapping the Browser Refresh Event in my JSP file

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
default methods vs abstract class 1 118
getting param value 7 57
caughtSpeeding java challenge 16 139
Limiting the number of characters a user can type in a text field 6 61
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
Giving access to ESXi shell console is always an issue for IT departments to other Teams, or Projects. We need to find a way so that teams can use ESXTOP for their POCs, or tests without giving them the access to ESXi host shell console with a root …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

808 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