Two Laptop Bag*
The moose likes Servlets and the fly likes Calling Init and Destroy Explicitly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Calling Init and Destroy Explicitly" Watch "Calling Init and Destroy Explicitly" New topic
Author

Calling Init and Destroy Explicitly

Rahul Juneja
Ranch Hand

Joined: Aug 03, 2002
Posts: 425
Guys,

Can we explicitly call Servlet init() or Destroy() method. If possible please tell me how is this possible.

Thanks,
Rahul


Rahul Juneja
ThoughtClicks - http://techlabs.thoughtclicks.com
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
The init and destroy methods are there for the servlet container to use. You can certainly call them but it would make no sense to do so.
What is it that you think you could accomplish?
Bill
Rahul Juneja
Ranch Hand

Joined: Aug 03, 2002
Posts: 425
William,

I was just curious as this was asked to in the interview. and can yopu please through some more light on this as when init() will be explicitly called, I mean how can we perform this thing.

Thanks,
Rahul
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
Init is called by the servlet container when the container (init)ially loads the servlet (e.g. when the app server instance is started or the application is deployed and restarted). From this you can guess what destroy does. This is why Mr. Brogden asked what you hope to accomplish by doing this? Generally, these methods perform application specific tasks in relation to start up and destruction like load static data from a database and store it in the application context. If you have a need for this data, you would put it into the init method. Since this has already been done, there would be no need to call it again. It's best to leave these methods for startup and destructrion as their name imply. Anything else you should create a new method in the servlet or even better implement it in a utility class.


No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling Init and Destroy Explicitly