can i call destroy() method in init() method of servlet

Answer Posted / sunil jaiswal

Yes, we can call destroy method from init method without any worry. Destroy method will be called up as calling any other method. Request shall still be process afterwards through service method(doGet, doPost etc). Because calling destroy method doesnt mean the killing the servlet instance. Calling the init, service and destroy method is in the specification of servlet lifecycle. So we can not alter those specification through outside. Once the servlet container thinks the servlet is of no use at some time(at the server shutdown) the container surely will be calling up the destroy method prior to destroy the servlet instance.

Is This Answer Correct ?    10 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is called servlet container?

665


How the typical servlet code look like ?

636


Why do we use sendredirect() method?

550


What is the use of java servlet api?

602


Name the different ways of session tracking.

569






what do you understand by url rewriting?

548


What do you mean by mime type?

553


When using servlets to build the HTML, you build a DOCTYPE line, why do you do that?

568


Describe some assignments that are executed by servlet container?

585


Whether we can get deadlock situation in servlets?

578


What is the inter-servlet communication?

702


How to handle exceptions thrown by application with another servlet?

615


When a client request is sent to the servlet container, how does the container choose which servlet to invoke?

574


Explain the differences between jsp and servlet.

545


What’s the difference between forward() and sendredirect() methods?

575