• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

either implements Serializable or HttpSessionActivationListener

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On p.260 of Head First Servlet,

make sure your attribute class types are Serializable... if they are not Serializable, have your attribute object class implement HttpSessionActivationListener...


Does it mean an attribute class can either implement Serializable interface or HttpSessionActivationListner for session migration?
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it looks like it; either make your seesion objects serializable so the container can serialize them or use HttpSessionActivationListener and write the code to persist and restore data yourself.

Note that although this constitute a very good guideline to insure that your application can run inside containers configured differently, you can safely ignore this if your Sessions are kept in memory all the time; they will never get serialized, passivated or activated.

Do not put too much stuff in your session anyway. I usually only put a userid in the session.


javax.servlet.http
Interface HttpSessionActivationListener

All Superinterfaces:
EventListener

public interface HttpSessionActivationListener
extends EventListener

Objects that are bound to a session may listen to container events notifying them that sessions will be passivated and that session will be activated. A container that migrates session between VMs or persists sessions is required to notify all attributes bound to sessions implementing HttpSessionActivationListener.

Since:
2.3

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic