You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Stefanos Karasavvidis <st...@multimedia-sa.gr> on 2001/07/10 23:11:28 UTC

getting same context accross virtual hosts

I'm using tomcat 3.2.2 with several configured virtual servers in one JVM.
I want to share an object across the various virtual hosts.

I'm using for this the
getServletContext().setAttribute(name,object)
in one servlet, and then I try to retrieve this object from a servlet in 
another virtual host with
getServletContext().getContext(uri).getAttribute(name)

well, it doesn't work, and this is because each 
getServletContext().getContext(uri) call returns a different instance of 
org.apache.tomcat.facade.ServletContextFacade depeding on the virtual 
host the sevlets are called from

for the uri, I tried several "versions", using the context name (say 
foo) like "/foo" and the virtual servers name like
"/host1/foo" and the ip address like "/ip/foo".
 For the same virtual host, all these uri return the same instance, 
except from the virtual host the attribute
was first set which returns a different instance for the uri's with the 
hostname.
Across the virtual hosts, the instance is always different

How do I specify the uri to get the same (and correct) instance of my 
context??

This method of information sharing was introduced for this purpose, 
wasn't it??

Stefanos