aspose file tools*
The moose likes Servlets and the fly likes session.getLastAccessedTime() = -1  ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "session.getLastAccessedTime() = -1  ??" Watch "session.getLastAccessedTime() = -1  ??" New topic
Author

session.getLastAccessedTime() = -1 ??

Rich Smyth
Ranch Hand

Joined: May 30, 2002
Posts: 87
I have a HttpSession object called session.
Why would session.getLastAccessedTime() and session.getCreationTime() return -1. What does -1 represent? Is my session in some weird state? I cannot find a reference to this return value in the API Doc. (btw, session.isNew == true).
TIA
Rich
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
I would say that -1 means there was no previous access - perfectly logical since the session is new.
Rich Smyth
Ranch Hand

Joined: May 30, 2002
Posts: 87
Sorry, please let me start again.
session.isNew() == false
(I said the opposite in my original post)
Does session.getCreationTime() == -1 mean that the session has not been created yet?
Rich
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Now I'm mystified... according to the source code, a new HttpSession should have a creation time of 0. The only place -1 appears is for the initial value of:
maxInactiveInterval = -1;
Bill
Rich Smyth
Ranch Hand

Joined: May 30, 2002
Posts: 87
Mystery Solved.
Bill's response prompted me to take a closer look at my session object.
Turns out my session is a StrutsTestCase (servletUnit) implementation of HttpSession. In that implementation, called HttpSessionSimulator, getCreationTime() and getLastAccessTime() always return -1 for valid sessions!
Thanks Bill,
Rich
 
wood burning stoves
 
subject: session.getLastAccessedTime() = -1 ??