aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Dealing with back buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Dealing with back buttons" Watch "Dealing with back buttons" New topic
Author

Dealing with back buttons

Sam Gardner
Ranch Hand

Joined: Jul 22, 2008
Posts: 48
Hey all-

I am working on a project that involves implementing a fairly lengthy survey.

Currently, I am using session variables and requests that are read on a single JSP page to display the various questions. The problem I am running into shows up when the user uses the back button. I can give each "page" a modified URL so that the browser will display the HTML shown at the previous page (at this point it "looks correct"), but it doesn't actually reevaluate the Java code or restore/modify any of the session parameters correctly.

This results in unpredictable behavior when the user tries to do anything on the returned-to page, so I'd like to do something that would warn the user not to use the back button, and instead use the navigation controls that we implemented to go back to a previous survey page.

Does anyone have any idea how this sort of thing could be implemented, preferably with no or minimal JavaScript?

Thanks a lot for any help/suggestions.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Use post to go from page to page and use the correct expires headers.

Eric
Sam Gardner
Ranch Hand

Joined: Jul 22, 2008
Posts: 48
Eric Pascarello wrote:Use post to go from page to page and use the correct expires headers.

Eric


The way my code currently functions (correctly, minus the back button issue) is such:

A session variable is set (session.setAttribute("current", question_number)) that is read by the server to determine which question should be displayed.

The form is submitted, a second page processes it and determines the next question that should be displayed, and changes the "current" session attribute accordingly.

The second page redirects back to the first page, which displays a new question based on the new, modified "current" attribute.

I've tried setting the response fields to disable caching using:


but the session variable from the page the user goes back from is still set (ie, the "current" variable is +1 from where it should be after the back button is pressed). What I am guessing needs to happen is that session variable needs to expire after the original page is left, but I have no idea how to go about doing that.

Do you have any thoughts or a link to a tutorial so that I can do this correctly without resorting to JavaScript hacks?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
name='cache-control' value='no-cache, no-store, must-revalidate'

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dealing with back buttons