session abandoned?

S

skijor

How do you detect when a user has abandoned a JSP session? In this
case a user has selected items from a catalogue and included them in a
shopping cart (cart table). If the user never checks-out and
disappears I want to clean the shopping cart table.
 
R

Roger Lindsjö

skijor said:
How do you detect when a user has abandoned a JSP session? In this
case a user has selected items from a catalogue and included them in a
shopping cart (cart table). If the user never checks-out and
disappears I want to clean the shopping cart table.

You could create your own HttpSessionListener which will be notified of
when sessions are created or destroyed.

For an example, see:
http://www.stardeveloper.com/articles/display.html?article=2001112001&page=1

//Roger Lindsjö
 
A

Arne Vajhøj

skijor said:
How do you detect when a user has abandoned a JSP session? In this
case a user has selected items from a catalogue and included them in a
shopping cart (cart table). If the user never checks-out and
disappears I want to clean the shopping cart table.

If you store the cart in memory in the session you get rid
of it automatically.

If you want to persist and still wipe out if the session
disappears, then the session listener is the right solution.

Arne
 
M

Mike

Yes. I looked at it and it's simple.

If you store the cart in memory in the session you get rid
of it automatically.

If you want to persist and still wipe out if the session
disappears, then the session listener is the right solution.

Arne
 
S

skijor

It doesn't work very well in Apache Tomcat 6.0.10.

Seems to get called with a different session id that was used to
persist my cart. I have only one session since deploying the servlet
yet there seems to be two session id's.
 
S

skijor

I take that back. It seems to get invoked every 7 minutes or so.
Latest invocation was called with correct sessionId. Someone must have
hit my test site....
 
S

skijor

What happens to stale sessions if the servlet container (Tomcat
6.0.10) is re-started?
 
L

Lew

skijor said:
What happens to stale sessions if the servlet container (Tomcat
6.0.10) is re-started?

In general, nothing - they're gone.

I've heard of persistent sessions, but I've not stumbled across one. Doesn't
seem like it'd be too hard to implement one, though I can't say as it seems
all that useful and could be harmful. It'd probably be better to simulate
such a thing by having a profile, and storing relevant session data with the
profile. That way a "session" in application terms can resume over separate
HTTP sessions, even from different client locations.

Layers.

A session in application terms is defined within the application domain,
homonymic terms relevant to, say, the transport protocol layer are really
about a different thing.

Figuring out how to get those lower layer sessions or packets or connections
or whatever to support the application-domain abstractions is what earns us
the big bucks.
 
S

skijor

I've heard of persistent sessions, but I've not stumbled across one.

Works in Tomcat. SessionHandler implementations will receive
sessionDestroyed() callbacks for session ID's that were created before
restarting the container.
Figuring out how to get those lower layer sessions or packets or connections
or whatever to support the application-domain abstractions is what earns us
the big bucks.

Isn't that what cookies are for?
 
A

Arne Vajhøj

skijor said:
Works in Tomcat. SessionHandler implementations will receive
sessionDestroyed() callbacks for session ID's that were created before
restarting the container.

Remember that this is for a "soft" restart. Pulling the power cord
will not get sessionDestroyed called.
Isn't that what cookies are for?

Cookies or URL rewriting are the implementation.

But the container does all the work of:
- using cookies or URL rewriting to maintain an abstraction in form of
the session object
- keeping track of which sessions are authenticated for what web apps

So I think it is the container developers that must be making the big
bucks.

Arne
 
A

Arne Vajhøj

Lew said:
I've heard of persistent sessions, but I've not stumbled across one.
Doesn't seem like it'd be too hard to implement one, though I can't say
as it seems all that useful and could be harmful.

Most containers has the capability to either persist session
to database or to replicate sessions to memory in other cluster
members. It is obviously not on by default.

http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html

tells how to do it with Tomcat.

It do have an impact on performance. But if you need to keep
sessions over a server crash or your load balancer does not
support sticky connections, then it is a must.

Arne
 
S

skijor

It do have an impact on performance. But if you need to keep
sessions over a server crash or your load balancer does not
support sticky connections, then it is a must.

what is a sticky connection?
 
A

Arne Vajhøj

skijor said:
what is a sticky connection?

I should have said sticky sessions.

When the load balancer routes requests from the same
client to the same app server.

Arne
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top