Thanks for that.

You mentioned that a database connection should be in the init method.
I was wondering how this would be possible if you different users
logging in under different usernames and passwords, i.e. how to
initiate the different passwords and usernames.

-----Original Message-----
From:   Balogh Andras [mailto:[EMAIL PROTECTED]]
Sent:   Monday, April 12, 1999 5:33 PM
To:     [EMAIL PROTECTED]
Subject:        Re: another dumb question from a blonde

Hi !!
-----Original Message-----
From: Sam Rose <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Sunday, April 11, 1999 11:46 PM
Subject: another dumb question from a blonde


>I know this is going to seem dumb but...
>
>I initiate a servlet like this
>
>public void init(ServletConfig config) throws ServletException {
>                super.init(config);
>}
>
>Should I also be destroying the servlet at the end of the code, or
>does this mess up my threads or is it the other way round?
>

I will try to answer this question a little bit more spefic:

in the init() method you should  initialize global variables like
a database Connection. The init() method executes only onces
when the servlet is loaded.
Only the service() ( doGet(),doPost() ) methods are executed
for every user request.
After a time the WebServer managing Servlets will decide
to unload(destroy) your servlet.
In this case the destroy() method is invoked. So just before
the Servlet is Unloaded the destroy method is invoked.
So if you declared something in the init method like
Connection you should (have to) take care of it :
     ex .
public  void destroy(){
               super.destroy();
               Connection.close();
               }
In other cases just use:
public  void destroy(){
               super.destroy();
               }
That's all.

BUT in the past i didn't know anything about this destory() method.
So i didn't use it and my servlets where doing fine.
So if you want to be proud that your servlets are clean you should
use the destroy() method.
Best wishes,
                            Andras

_______________________________________________________________________
____
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

___________________________________________________________________________
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

Reply via email to