When would you use one over the other and why? Thanks in advance, Buk
posted 11 years ago
The ServletContext is shared throughout an entire context. You would store data in it that is not modified by user actions (unless you want the changes to be global)... DataSources, read-only caches, etc. The Session object exists for each user coming through the context. It is useful for storing user state data such as a User object of some sort, or wizard-style temporary variables between pages, etc. Try to put more data in the ServletContext rather than the Session context. Since each visitor has its own session, session objects can really build up memory usage. Hope this helps.