Reputation: 52
I am editing a class that is mean to be placed into the session of a servlet use as a key for a hastable of other objects. I do not know what the minimal requirements for an object which can be placed into the HttpSession. what are the minimal requirements for an object which can be placed into the HttpSession?
Upvotes: 0
Views: 385
Reputation: 19445
All objects that are placed in a HttpSession should implement java.io.Serializable
.
That's really the only "minimal" requirement.
For scalability you generally want to minimise the overall size of objects that you place in the session as well.
Upvotes: 0
Reputation: 692131
It should be thread-safe (or at least you should be aware that it can be used by several threads concurrently).
If you plan to save the session to disk or to share it among a cluster of servers, then it should also be Serializable.
And if that object is supposed to be used as a key of a HashMap, then it should override hashCode()
and equals()
properly, and it would be a good idea to make it immutable.
Upvotes: 1