I see from the 2.2 APIs that is is possible for a servlet in one
context to access objects in other contexts:
public void init( ServletConfig config ) {
ServletContext localContext = config.getServletContext();
ServletContext otherContext = localContext.getContext( "someurl" );
Object o = otherContext.getAttribute( "foo" );
MyClass c = (MyClass)o; <---------- fails
}
My problem is that I cannot now cast object o to a local class type
MyClass, since even though the fully qualified class names will match,
the class instance as was added to the other context (using
setAttribute( "foo", OBJ )) was itself loaded via a DIFFERENT class
loader to the one which loaded MyClass in the local context. So I get
a class cast exception above, in 1.2 runtimes anyway. 1.1 runtimes
may behave differently(??)
Is there any way around this? If not, doesn't it imply that resources
cannot be shared across contexts. I could use runtime typing and
reflection to access the object, but that's a pain.
On a related note, is there a better design here, where I want a
resource to be accessible to distinct contexts. Maybe a third,
"helper" context is better?? Is there a way to have "global" data in
a servlet container??
Any pointers appreciated...
stu
--
Stuart Maclean, Research Associate
University of Washington
ITS Research Program, College of Engineering
Box 352500
Seattle, WA 98195-2500
Tel: (206) 543-0637
http://www.its.washington.edu
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html