Can we call destroy() method inside the init() method? What
happens when we do so?

Answer Posted / amitasite

One can call destroy method from init method. One scenario
in which you would like to call is some resource is looked
up once in init() method and cleaned in destroy() method. If
exception is thrown before it finishes as servlet is not
brought in service, container won't call destroy method. so
to keep resource clean you can call destroy() method from init()

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is meant by a web application

514


What is servlet container. how it works?

584


What is difference between jsp and servlet?

611


What is the web server used for running the Servlets?

563


What do you mean by scope object and what are its types?

549






Why doesn’t a servlet include main()? How does it work?

606


What is servlet in tomcat?

535


What are the various ways of session supervision in servlets?

496


Why don't we write a constructor in a servlet?

565


Write a hello world program using servlets.

561


Why is Servlet so popular?

591


Which HTTP method is non-idempotent?

599


What is the advantage of Servlets when compared with other server side technologies?

1833


Explain is servlet mapping?

558


Which exception is thrown if the servlet is not initialized properly?

559