This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Servlets and the fly likes Session lost on page refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session lost on page refresh" Watch "Session lost on page refresh" New topic

Session lost on page refresh

koen ja

Joined: Oct 15, 2007
Posts: 10

I have a webapplication deployed on WAS5.1;
it has a page that has to auto-refresh every 30 seconds.

To do so, i put two attributes on the incoming request for the page:

request.setAttribute("refresh_url", "my_url");
request.setAttribute("refresh_time", "30");

So far, so good. The page loads and refreshes every 30 seconds.

Is it required to "enable cookies" in the webcontainer? Then
everything works.
But then I have the problem that the user needs to shut down his
entire browser
to be sure that all session data is cleaned after logout.
If he does not, some data is still present in the session after a new
(from the browser cookie I guess?)

When I try the same without "enable cookies", my initial session gets
lost on page refresh.
(and a new one is created on every refresh).

Is there a way to maintain my initial session then?

I already tried:
- adding ";jsessionid=<THE_SESSION_ID_OF_THE_INITIAL_REQUEST>" to the
- getting the jsessionid cookie from the initial request and posting
this to the response

Many thanks!
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Are you using instance variables somewhere and that is carrying over?

So much trouble in the world -- Bob Marley
koen ja

Joined: Oct 15, 2007
Posts: 10
An object is saved in session.

Then, when I logout (session.invalidate())
and log in again (even with another user!),
the object is in session scope again.

I don't know alot about cookies..
How does this object get into session scope again?

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

I'm going to move this to our Websphere (WAS) forum.
I'm not very familiar with WAS but I've heard in passing that it has a proprietary mechanism for keeping sessions alive with cookies that is beyond what is in the servlet spec.

I could be wrong about this and the folks in the WAS forum will know better.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
subject: Session lost on page refresh
It's not a secret anymore!