This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Back Button detection with Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Back Button detection with Servlet" Watch "Back Button detection with Servlet" New topic
Author

Back Button detection with Servlet

Kelley Koszegi
Greenhorn

Joined: Aug 20, 2001
Posts: 27
Hello,
Looking through this group and others, I see that disabling the browser back button is not 100% possible. But is it possible for a servlet to somehow 'detect' that the back button was pressed? Are there any tricks to do this?
Just for background: the application I am working on will fail sometimes when using the back button because information is taken both from a link on the page and the session. When using the back button, the session data will become outdated and may not be compatible with the link parameters of the current page.
Any suggestions would be appreciated. TIA!
--Kkoszegi


Kelley Koszegi<br />Sun Certified Java Programmer
Brian Blesbok
Greenhorn

Joined: Sep 03, 2001
Posts: 9
you can use:
history.go(1);
in the header of each and every servlet page - include it in a js file if you want... that way, when a user presses the back button, on trying to load the provious page, the browser goes forward one ie: stays on the current page.
In IE this works sweet, and there is no page flicker really -but NutScrape has a bit of a flicker - but both work.
This is the only way I have found of disabling the back.
Another way, is to code your app so that it handles the situation where someone has pressed the back button. always code for the worst case scenario -if a user can break it, they will - and complain they will also!!
cheers
Kelley Koszegi
Greenhorn

Joined: Aug 20, 2001
Posts: 27
Hello,
Thanks for your reply, Brian. Things have changed a little and disabling the back button is not a possibility.
Like I said before, I am interested in finding out how the servlet could detect that the back button was pressed. Does anyone have an idea as to how I could do that?
Thanks,
--KKoszegi
Kareem Gad
Ranch Hand

Joined: Aug 06, 2001
Posts: 89
To my knowledge its not actually possible to have some browser listener and deal with the events happening on the browser .. back or no back ..
its all client side.
Servlets are server side remember ?

------------------
KaReEm


<b><i>KaReEm</i><br /><ul type="square"><li>SCJP-Free Range Web Developer <br /></ul></b>
Steve Snodgrass
Greenhorn

Joined: Jun 12, 2001
Posts: 27
We use javascript and hidden fields to detect the condition where a page is loaded from the browser cache as opposed to the server. If it is we pop up an alert informing the user that they should hit refresh to get the latest data or unexpected results may occur. Alternatively you could post a form to the servlet upon this condition so it is aware of the situation and handles it.
Our app has never been tested with Netscape so I am not sure if this would work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Back Button detection with Servlet
 
Similar Threads
Session problem in websphere
Problem in displaying value from session object
does sendRedirect() lose session ?
jsp logout problem
AJAX JSP TagLib Interaction?