----- Original Message -----
From: "Bo Xu" <[EMAIL PROTECTED]>
> - I guess perhaps Servlet container uses something like the
following:
> ...
> URL [] urls=new URL[]{new URL("file:ServletPath/")};}
> ClassLoader cl=new URLClassLoader(urls);
> Class c=cl.loadClass("myServlet");
> myServlet sServlet=(myServlet)c.newInstance();
> * so could anybody tell me:
> does Servlet container use the above way to make a instance
for my
> Servlet class?
I have seen the source code for a servlet container known as Paperclips and
it uses the method class.newInstance() to create a new instance of the
servlet class. In my opinion other containers must also be doing the same
thing.
> because I want to know how to keep a object
> refrenced by a field in my Servlet class in JVM as long as possible.
I think putting the reference in the ServletContext can help you.
Even if your servlet instance is destroyed and a new instance is created by
the container, you can check for the attribute in the init() method of your
servlet.
But be forewarned. If there is a reload of the web app & the object
referenced is not an instance of a class on the classpath, you may get
ClassCastException.
> Bo
> Dec.31, 2000
Regds,
Gokul
___________________________________________________________________________
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