日期:2014-05-20  浏览次数:20893 次

关于servlet之间通讯有点问题不明白
最近再看servlet的东西,但是servlet之间的通讯有点不明白:下面是我在一个网站上看到的一段话,虽然能看懂字面意思,但是还是比较晕,高手给详细解释下。

Note that in Java the identity of a class is not only defined by the class name but also by the ClassLoader by which it was loaded. Web servers usually load each Servlet with a different class loader. This is necessary to reload Servlets on the fly because single classes cannot be replaced in the running JVM. Only a ClassLoader object with all loaded classes can be replaced.

This means that classes which are loaded by a Servlet class loader cannot be used for inter-Servlet communication. A class literal FooServlet (as used in a type cast like "FooServlet foo = (FooServlet)context.getServlet("FooServlet")") which is used in class BarServlet is different from the class literal FooServlet as used in FooServlet itself.

这是这篇文章的url:http://www.novocode.com/doc/servlet-essentials/chapter3.html#ch_3_1

------解决方案--------------------
主要是说不同的类加载器加载的类处于不同的命名空间中