Announcement Announcement Module
Collapse
No announcement yet.
Browser Back Button Issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Browser Back Button Issue

    Using a SimpleFormContoller, I have a search form that contains various parameters, much like this forum's search screen. Upon entering various critieria, a list of availble links (hits) are displayed. When the user clicks on a link the browser moves to the page accoringly - no problem.

    But when I press the browser's back button, I receive the following error page:

    The page cannot be displayed
    The page you are looking for is currently unavailable. The Web site might be experiencing technical difficulties, or you may need to adjust your browser settings.

    ...

    If I do a refresh, the page displayes correctly without the previously entered parameters. Does anybody know why this is happening? Is there anyway to avoid receiving an error page on pressing the Back Button?

    Thanks!

  • #2
    Do you get a server error (and stacktrace)? Are you using IE - check it's not a browser issue - check for IE updates. Also try Mozilla or Firefox. If you still get problems, trying sniffing the traffic with Ethereal to see what's going on.

    Comment


    • #3
      Code:
      Are you using IE - check it's not a browser issue - check for IE updates.
      Interesting enough, everything works fine using Netscape 7.2. IE 6.0 on the otherhand is messing up. As suggested, I'll check for updates, etc...

      I'll report my findings if I'm able to find a fix.

      Thanks.

      Comment


      • #4
        My solution ... and another question!

        I was having exactly the same problem, namely:
        1. User submits an HTML form that does a search.
        2. User sees a list of search results, each hyperlinked to a details screen.
        3. User clicks one of the "details" hyperlinks.
        4. User sees the details screen.
        5. User clicks browser's "Back" button to return to the screen in Step 2.
        6. Browser gives confusing message about having to resubmit POST data. In Firefox this is a dialog box with OK/Cancel, and IE this is a white screen with the message:

        "Warning: Page has Expired The page you requested was created using information you submitted in a form. This page is no longer available. As a security precaution, Internet Explorer does not automatically resubmit your information for you. To resubmit your information and view this Web page, click the Refresh button."

        My search screen controller (indirectly) extends Spring's AbstractController (see http://static.springframework.org/sp...ontroller.html), which by default has cacheSeconds = -1, meaning that the response (in this case generated by submitting the search screen form) will contain no cache headers. Presumably this tells the browser not to cache that response (i.e. the page of search results), which explains why when the user tries to go back to that page, the browser says "uh-uh, you have to resubmit the form first".

        I got around this by creating my own subclass of SimpleFormController that defaults the cacheSeconds property to a positive value:

        Code:
        public abstract class CachingSimpleFormController extends
            org.springframework.web.servlet.mvc.SimpleFormController
        {
          private static final int DEFAULT_CACHE_SECONDS = 1;
        
          public CachingSimpleFormController(...) {
            setCacheSeconds(DEFAULT_CACHE_SECONDS);
            ...
          }
        
          ...
        }
        I didn't have to do this in any of my other abstract controller superclasses, presumably because none of them handle POST requests.

        So now the back button works nicely in both Firefox and IE. What I would like to know is, why does it make no difference what positive number of seconds I specify? I tried setting it to 10 seconds, and the back button worked just as well regardless of whether I waited more or less than 10 seconds before clicking it. Anyone know why this is?

        Andrew

        Comment


        • #5
          Very useful solution ...
          Setting cache seconds solved all my back button problems...

          Thanks
          MP

          Comment


          • #6
            And the positive integer in setCacheSeconds method doesnot do anything at all...
            Probably a bug !

            Comment


            • #7
              back button issue

              Hi Andrew

              I read your post regarding back button issue in AbstractController.

              I am using controller which is extending AbstractWizardFormController.I tried setting setCacheSeconds(DEFAULT_CACHE_SECONDS); in my controller.On click on back button,it goes to previous page ,but once user enters the values n submit the form,it is detecting invalid submit and displays the same page again without having any user input.The next time user enters any values,it work sproperly

              Can you guide me how to resolve back button in my abstract controller.

              Comment


              • #8
                back button issue

                Hi Andrew

                I read your post regarding back button issue in AbstractController.

                I am using controller which is extending AbstractWizardFormController.I tried setting setCacheSeconds(DEFAULT_CACHE_SECONDS); in my controller.On click on back button,it goes to previous page ,but once user enters the values n submit the form,it is detecting invalid submit and displays the same page again without having any user input.The next time user enters any values,it work sproperly

                Can you guide me how to resolve back button in my abstract controller.

                Comment


                • #9
                  My current thinking on this is that the best solution is to use the redirect on post pattern.

                  For an example of how this can be implemented in Spring MVC, use Spring Roo to generate a simple web app, then look at the "create" methods in your controller(s), which redirect to a GET request after receiving form data via a POST request.

                  Comment


                  • #10
                    Thank you Andrew for the reply.

                    As I don't have any knowledge on Spring Roo,it would be difficult for me to implement this solution.

                    Can we solve this using abstract wizard controller .


                    Regards,
                    Gayatri

                    Comment


                    • #11
                      I've never used the Spring MVC wizard controllers, but the manner in which views are resolved is independent of how your controllers are implemented.

                      In Spring MVC, redirecting to a GET request after a POST request is achieved via a special prefix in the logical view name returned by your controller. See this part of the reference guide for details:

                      http://static.springsource.org/sprin...vc-redirecting

                      AbstractWizardFormController is deprecated in Spring 3.x. If you need a wizard-style interaction, I recommend you use Spring Web Flow instead. There's a bit of a learning curve, but once you've "got" it, you get a lot of nice features out of the box, like correct back button handling.

                      Comment

                      Working...
                      X