JSP: Session parameters vanish on refresh. How do I keep them on refresh?

Discussion in 'Java' started by Per Magnus L?vold, Oct 7, 2004.

  1. Hi!
    I'm working on a JSP application. Using JDBC I query for a certain
    background program to finish populating a table.
    This takes a while, so I am trying to do a refresh page that updates
    with the latest results.
    For refreshing the page, I use:
    ***
    <head>
    <META HTTP-EQUIV="REFRESH" CONTENT=30>
    <title>my page</title></head>
    ***

    This does the trick of refreshing the web page every 30 seconds. BUT
    the problem is that all the parameters I have passed to the page
    dissappear on the refresh..! So my code stops working. :-(

    How can I set the parameters so that they still can be retreived after
    a refresh?

    The webserver supports servlet 2.0, and I have tried setting the
    parameters with:
    ***
    session.putValue("MyParam","MyValue");
    ***

    When I after refresh try:
    ***
    String myParam = (String)session.getValue("MyParam");
    ***
    ....myParam is empty.

    Hope someone can help me here! :)

    Regards, Per Magnus
     
    Per Magnus L?vold, Oct 7, 2004
    #1
    1. Advertising

  2. Re: JSP: Session parameters vanish on refresh. How do I keep themon refresh?

    Per Magnus L?vold wrote:

    > Hi!
    > I'm working on a JSP application. Using JDBC I query for a certain
    > background program to finish populating a table.
    > This takes a while, so I am trying to do a refresh page that updates
    > with the latest results.
    > For refreshing the page, I use:
    > ***
    > <head>
    > <META HTTP-EQUIV="REFRESH" CONTENT=30>
    > <title>my page</title></head>
    > ***
    >
    > This does the trick of refreshing the web page every 30 seconds. BUT
    > the problem is that all the parameters I have passed to the page
    > dissappear on the refresh..! So my code stops working. :-(
    >
    > How can I set the parameters so that they still can be retreived after
    > a refresh?
    >
    > The webserver supports servlet 2.0, and I have tried setting the
    > parameters with:


    If your servlet container doesn't support at least version 2.2 of the
    servlet API then I would ditch it for something a little less dusty.
    Tomcat 3 supports Servlet 2.2, Tomcat 4 supports Servlet 2.3, and Tomcat
    5 supports Servlet 2.4 (the latest). All are available without charge,
    under (I believe) the Apache open source license.

    Do note, however, that the putValue() and getValue() methods of
    HttpSession are deprecated in favor of setAttribute() and getAttribute()
    in recent versions of the Servlet API. I don't have API docs old enough
    to determine whether there is any difference in behavior.

    > ***
    > session.putValue("MyParam","MyValue");
    > ***
    >
    > When I after refresh try:
    > ***
    > String myParam = (String)session.getValue("MyParam");
    > ***
    > ...myParam is empty.


    Do you mean null? The two are very different.

    > Hope someone can help me here! :)


    Most likely each refresh request is ending up in a new session. This
    would indeed be quite likely if the original request caused a new
    session to be created for it: if the request did not include information
    binding it to a session (cookie / query parameter / whatever) when it
    was originally issued, then it will still not have such information when
    it is reissued to refresh the page. A possible solution, then, is to
    adjust your interface design to ensure that the client is positively
    enrolled in a session before requesting this needs-to-be-refreshed page.
    You can also test on that page whether the session .isNew(); if it is,
    then you are likely to have the kind of problem you describe. (Note: I
    don't know at which version of Servlet HttpSession.isNew() was
    introduced. The v 2.3 API docs don't record that information, but the
    method has been there since at least 2.2.)


    John Bollinger
     
    John C. Bollinger, Oct 8, 2004
    #2
    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. Greg
    Replies:
    0
    Views:
    697
  2. Angus Parvis
    Replies:
    0
    Views:
    634
    Angus Parvis
    Aug 26, 2004
  3. sridhar kumar ch
    Replies:
    1
    Views:
    8,702
  4. sridhar kumar ch
    Replies:
    0
    Views:
    819
    sridhar kumar ch
    Jun 28, 2006
  5. F. GEIGER
    Replies:
    2
    Views:
    366
    F. GEIGER
    Sep 30, 2003
Loading...

Share This Page