On Fri, 11 Jan 2002, Chad Johnson wrote:

> Date: Fri, 11 Jan 2002 22:04:37 -0600 (CST)
> From: Chad Johnson <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: Tomcat Users List <[EMAIL PROTECTED]>
> Subject: RE: Sessions across contexts, is it possible?
>
> Hey,
>   What if we change the scenario a little bit.  Is is possible to share
> objects between contexts that reside in differant <host>
> blocks?  getContext() does not seem to work in that scenario.
>
> -Chad Johnson

No, virtual hosts are considered (by the servlet API) to be totally
independent.

If you want to delve into container-specific behavior, classes that are
loaded from a shared class loader in Tomcat (i.e. from the
"$CATALINA_HOME?lib"  directory, for example) are global to all web apps,
even across virtual hosts.  Static variables declared in such classes, for
example, have only one instance across all web apps.

However, I would *****strongly***** urge you to reconsider your overall
application architecture if you are tempted by depending on this kind of
feature (even though shared libraries of some sort are very commonly
implemented).  Dependence on global context like this (instead of writing
APIs to an abstract persistence layer) is just going to get you into
trouble later with scalability and maintainability issues.  You'd be much
better off designing your individual web applications as modularly as
possible -- delegate any required state sharing to mechanisms to get
common persistence layer objects from whatever storage mechanisms you are
using.

If you decide not to heed this advice (yes, I know, it is a lot more work
up front), then don't expect any sympathy from me when you run into
barriers trying to expand and enhance your application in the future.

Craig McClanahan



--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to