Andrey Myatlyuk wrote:
>
> Hello Vladimir,
>
> Thursday, March 15, 2001, 12:25:24 PM, you wrote:
>
> VG> What you describe should work... Unless Tomcat web-app CL doesn't
> VG> adhere to standard CL delegation rules. Where did you put your classes?
> VG> I think $TOMCAT_HOME/classes is automatically appended to system classpath
> VG> by startup script.
> VG> I don't think _bootstrap_ CL is the one
> VG> that's loading classes if you put them on system classpath.
> VG> Probably it's SystemClassLoader. You can test
> VG> it like this from your servlet to find out what's going on:
>
> VG> _statesBean=
> VG> getServletContext().getAttribute(StatesBean.STATES_BEAN_NAME);
> VG> ClassLoader cl = _statesBean.getClass().getClassLoader();
> VG> if (cl.getParent() == null)
> VG> System.out.println("Bootstrap Class Loader");
> VG> if (cl == ClassLoader.getSystemClassLoader())
> VG> System.out.println("System Class Loader")
> VG> if (cl == this.getClass().getClassLoader())
> VG> System.out.println("Current WebApps Class Loader");
>
> In case StatesBean in web-inf/classes - "Current WebApps Class Loader"
> In case StatesBean in %CLASSPATH% - "System Class Loader"
>
> VG> BTW, did you try to use reflection like I suggested before
> VG> (scroll down...)?
>
> Not yet. :)
>
> <from previous post>
> > >> Now, when your servlet class is loaded, Tomcat asks the webapp class
> > >> loader to load it. Following the standard Java delegation model, the web
> > >> app class loader first asks it's parent class loader to try to find the
> > >> class -- and so on up the hierarchy. If your servlet class is actually in
> > >> WEB-INF/classes or WEB-INF/lib, all of these attempts to delegate upwards
> > >> will fail. Therefore, the web app class loader will load the class
> > >> itself.
> > >>
> > >> The same thing happens for every other class that your servlet references
> > >> -- it gets loaded by whichever class loader finds that class. If the load
> > >> happens from a class loader *above* the calling class's class loader, that
> > >> is fine. However, trouble occurs if you try the opposite direction,
> > >> because there are no links *downward* in the class loader hierarchy.
> </from previous post>
>
> I have my StatesBean loaded by SystemClassLoader. OK.
> MyServlet by WebAppLoader. Good.
>
> So when WebAppLoader reloads my servlet it should ask its parents
> about loaded class. Ang guess what? StatesBean loaded already with
> SystemClassLoader. What's wrong with it?
>
> Why do I get java.lang.NullPointerException in
> _statesBean=
> getServletContext().getAttribute(StatesBean.STATES_BEAN_NAME);
>
> after reloading servlets?
Dunno...
Could it be that Tomcat invalidates Context's contents???
>
> --
> Best regards,
> Andrey mailto:[EMAIL PROTECTED]