Browser back/forward button and Java Servlets

Discussion in 'Java' started by John, Apr 12, 2007.

  1. John

    John Guest

    Hi everybody,
    for my web-application (it must currently work only under IE6) I have
    a servlet that intercepts user's HTTP GET requests for a typical
    search result page, which contains a paging mechanismus for navigating
    between the result pages (e.g. << 1 2 3 4 5 ... >> ).

    When the user clicks on this navigation, the JSP send a GET request to
    a servlet wich does some buisiness logic - in particular it logs (with
    log4j) how many times an user navigates between the several pages and
    then sends the response back to the client with the next search
    results page. Everything works fine.

    BUT if the user hits the browser's back/forward buttons, the servlet
    which contains the counter for the log file will be never called from
    the JSP, and so the counter will not increase its value for the log-
    file.

    I must handle this back/forward event (as well as, when the user
    clicks the right mouse button to navigate the history - back or
    forward).

    I have no idea how to catch the event and calling the servlet for
    incrementing the counter.... and the business sets me more and more
    under pressure :-(

    Does anybody has an idea, suggestion, or a link with an example?

    Thank you very much for your suggestions :)
    John
    John, Apr 12, 2007
    #1
    1. Advertising

  2. John wrote:
    > Hi everybody,
    > for my web-application (it must currently work only under IE6) I have
    > a servlet that intercepts user's HTTP GET requests for a typical
    > search result page, which contains a paging mechanismus for navigating
    > between the result pages (e.g. << 1 2 3 4 5 ... >> ).
    >
    > When the user clicks on this navigation, the JSP send a GET request to
    > a servlet wich does some buisiness logic - in particular it logs (with
    > log4j) how many times an user navigates between the several pages and
    > then sends the response back to the client with the next search
    > results page. Everything works fine.
    >
    > BUT if the user hits the browser's back/forward buttons, the servlet
    > which contains the counter for the log file will be never called from
    > the JSP, and so the counter will not increase its value for the log-
    > file.
    >
    > I must handle this back/forward event (as well as, when the user
    > clicks the right mouse button to navigate the history - back or
    > forward).
    >
    > I have no idea how to catch the event and calling the servlet for
    > incrementing the counter.... and the business sets me more and more
    > under pressure :-(
    >
    > Does anybody has an idea, suggestion, or a link with an example?
    >
    > Thank you very much for your suggestions :)
    > John
    >


    I'm guessing that what's going in is that the browser is loading a
    cached back page, so it goes back to the cached page and sends no
    request to the servlet. If this is the case, then sending a simple AJAX
    request using a window.onload handler to get the servlet to recognize
    the back should be sufficient.
    Joshua Cranmer, Apr 12, 2007
    #2
    1. Advertising

  3. John

    Randy Webb Guest

    Joshua Cranmer said the following on 4/11/2007 10:43 PM:
    > John wrote:
    >> Hi everybody,
    >> for my web-application (it must currently work only under IE6) I have
    >> a servlet that intercepts user's HTTP GET requests for a typical
    >> search result page, which contains a paging mechanismus for navigating
    >> between the result pages (e.g. << 1 2 3 4 5 ... >> ).
    >>
    >> When the user clicks on this navigation, the JSP send a GET request to
    >> a servlet wich does some buisiness logic - in particular it logs (with
    >> log4j) how many times an user navigates between the several pages and
    >> then sends the response back to the client with the next search
    >> results page. Everything works fine.
    >>
    >> BUT if the user hits the browser's back/forward buttons, the servlet
    >> which contains the counter for the log file will be never called from
    >> the JSP, and so the counter will not increase its value for the log-
    >> file.
    >>
    >> I must handle this back/forward event (as well as, when the user
    >> clicks the right mouse button to navigate the history - back or
    >> forward).
    >>
    >> I have no idea how to catch the event and calling the servlet for
    >> incrementing the counter.... and the business sets me more and more
    >> under pressure :-(
    >>
    >> Does anybody has an idea, suggestion, or a link with an example?
    >>
    >> Thank you very much for your suggestions :)
    >> John
    >>

    >
    > I'm guessing that what's going in is that the browser is loading a
    > cached back page, so it goes back to the cached page and sends no
    > request to the servlet. If this is the case, then sending a simple AJAX
    > request using a window.onload handler to get the servlet to recognize
    > the back should be sufficient.


    That won't work as the onload event isn't always fire when the page is
    retrieved from the cache.

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Apr 12, 2007
    #3
  4. John

    Adam Maass Guest

    "Joshua Cranmer" <> wrote:
    > John wrote:
    >> Hi everybody,
    >> for my web-application (it must currently work only under IE6) I have
    >> a servlet that intercepts user's HTTP GET requests for a typical
    >> search result page, which contains a paging mechanismus for navigating
    >> between the result pages (e.g. << 1 2 3 4 5 ... >> ).
    >>
    >> When the user clicks on this navigation, the JSP send a GET request to
    >> a servlet wich does some buisiness logic - in particular it logs (with
    >> log4j) how many times an user navigates between the several pages and
    >> then sends the response back to the client with the next search
    >> results page. Everything works fine.
    >>
    >> BUT if the user hits the browser's back/forward buttons, the servlet
    >> which contains the counter for the log file will be never called from
    >> the JSP, and so the counter will not increase its value for the log-
    >> file.
    >>
    >> I must handle this back/forward event (as well as, when the user
    >> clicks the right mouse button to navigate the history - back or
    >> forward).
    >>
    >> I have no idea how to catch the event and calling the servlet for
    >> incrementing the counter.... and the business sets me more and more
    >> under pressure :-(
    >>
    >> Does anybody has an idea, suggestion, or a link with an example?
    >>
    >> Thank you very much for your suggestions :)
    >> John
    >>

    >
    > I'm guessing that what's going in is that the browser is loading a cached
    > back page, so it goes back to the cached page and sends no request to the
    > servlet. If this is the case, then sending a simple AJAX request using a
    > window.onload handler to get the servlet to recognize the back should be
    > sufficient.


    Nocache HTTP response headers. I forget the exact format, but that should do
    the trick.
    Adam Maass, Apr 12, 2007
    #4
  5. John

    Sanjay Guest


    > Nocache HTTP response headers. I forget the exact format, but that
    > should do the trick.


    If I remember correctly, this won't work in Firefox, as it has some kind
    of cache (called back-forward cache?). Firefox caches pages even if you
    set no-cache in http headers.
    Sanjay, Apr 12, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sylvia sil
    Replies:
    1
    Views:
    577
    Curt_C [MVP]
    Dec 29, 2004
  2. Terry Olsen
    Replies:
    3
    Views:
    10,484
    nashlovebrown
    May 8, 2009
  3. Author
    Replies:
    6
    Views:
    3,012
    George
    Jan 22, 2009
  4. Simon

    back/forward button browser

    Simon, Mar 15, 2007, in forum: Javascript
    Replies:
    4
    Views:
    107
    Tom Cole
    Mar 15, 2007
  5. John
    Replies:
    3
    Views:
    210
    Sanjay
    Apr 12, 2007
Loading...

Share This Page