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

  • Thread starter Per Magnus L?vold
  • Start date
P

Per Magnus L?vold

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
 
J

John C. Bollinger

Per said:
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
(e-mail address removed)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top