Hi dear friends,
I have a question about the constructor of a Servlet class(its name is
myServlet.class):
* I find if I write a constructor:
- public myServlet(){...}
- public myServlet(int i){...}
- myServlet(){...}
- myServlet(int i){...}
I can complier myServlet.java, but when I run it, it seems that only
the following can work:
- public myServlet(){...}
it seems that others can not work.
* so:
- 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();
...
- when I test the above code in a Java Application(and use another
simple Java class mySimple.class to replace myServlet.class), I got
the same result:
I only can write "public mySimple(){...}", otherwise I wil get:
- "java.lang.InstantiationException: mySimple" for the following
constructor:
public mySimple(int i){...}
or
mySimple(int i){...}
- "java.lang.IllegalAccessException: mySimple" for the following
constructor:
mySimple(){...}
* so could anybody tell me:
does Servlet container use the above way to make a instance for my
Servlet class? because I want to know how to keep a object
refrenced by
a field in my Servlet class in JVM as long as possible.
Thanks in advance! Happy new year!:-)
Bo
Dec.31, 2000
___________________________________________________________________________
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