Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JSP: Session parameters vanish on refresh. How do I keep them on refresh?

Reply
Thread Tools

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

 
 
Per Magnus L?vold
Guest
Posts: n/a
 
      10-07-2004
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
 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      10-08-2004
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
downloads vanish meggie Computer Support 4 07-30-2006 07:50 PM
Object datasources vanish from rdlc data sources in web project Greg ASP .Net 0 11-21-2005 05:32 PM
XSL and java.xml.transform - spaces vanish, not able to use entities Angus Parvis Java 0 08-26-2004 04:59 PM
Problem: XP Home Logon Names Vanish - Cant Logon Graham Computer Support 0 01-24-2004 11:34 AM
[PMW 1.2] Dialog controls vanish upon editing F. GEIGER Python 2 09-30-2003 11:27 AM



Advertisments