Hi Guys, Can we write destroy() method in the init() method of a Servelt. if we can, what will happen? if we cant , why we cant?with regards, santh

Showing Answers 1 - 20 of 20 Answers

Mahesh

  • Jun 15th, 2006
 

hi santh,

        we cannot write destroy() method in the init() method..because init(),service(), and destroy methods are life cycle methods the servlet management  executable program in the servlet container(which is a part of webserver) is written like that ......

        so we can write the servlet by overriding these three methods individually

  Was this answer useful?  Yes

Veeren76

  • Aug 16th, 2006
 

Yes you can call destory() method from init(), although not advisable to do that.... u still can..... i dont see a need to call destory() method, ..... the life cycle methods are provided for application servers purpose, and are almost not required to be used by developers under normal circumstances.Veerendra Jote

  Was this answer useful?  Yes

suresh

  • Jan 2nd, 2007
 

You can call "destroy()" method in the servlet "init()". Actually destroy() is a servlet life cycle method which will be called by the container when the servlet instance is just before being distroyed. suresh g

  Was this answer useful?  Yes

Yes - you can call destroy() from init() like any other method.
For details check my answer to another similar question http://www.geekinterview.com/question_details/40017

  Was this answer useful?  Yes

atulkumar81

  • Apr 23rd, 2007
 

No, We cannot write destroy() method within servlet service() method because, all have to do different task init method call the instance object and destroy method make free that object from memory.

  Was this answer useful?  Yes

Rakesh.s

  • Sep 29th, 2007
 

Then what is the use of a Servlet? If we call the destroy method in init() it will kill the servlet instance, then how the service method occur. How it will process the request?

  Was this answer useful?  Yes

sampra

  • Mar 4th, 2008
 

No, We cannot write destroy() method within servlet service() method because, all have to do different task init method call the instance object and destroy method make free that object from memory.

  Was this answer useful?  Yes

Ya definitely you can call destroy() from init , but in that case it will be called as any other method it will execute the code in destroy() and will come back to init().The destroy() method is called by server when the servlet is about to get unloaded.

Dhruv

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions