can i call destroy() method in init() method of servlet
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / archana
yes, u can call destroy() method in init() of Servlet.
but calling destroy() in this way doesnt unload servlet
from servlet container.
Is This Answer Correct ? | 8 Yes | 4 No |
Answer / deepesh
Yes, We can call destroy() from init() method but after
coming out from the destroy() it will again process the init
() method like the life cycle has to be. Thus we can not
control the servlet life cycle, though we can call destroy
() from init().
Thanks.
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / yathirajulu
yes, we call destroy() in init(),because both are called once.
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / helper
Shekhar babu, if you don't know anything. why are you
answering questions. Just read the answers as you should be
able to analyze your abilities.
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / tanuj
yes,
but genricServlet init() method initialization is different
from overriding it by you (we should not orride it).
destroy() method is used for closing many connections as
itit() method is used for starting some database and other
things.
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / tanuj
Shekar babu is an disgrace to java community should never
blog answers,destroy() is just to inform what is to be done
when the service call is terminated it is like
on_service_destroy() what is to be done.
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / shekhar
no,we can't call destroy() in init() method.because of
init() and dstroy() methods are take care by web container
Is This Answer Correct ? | 7 Yes | 15 No |
What is the difference between a generic servlet and http servlet?
Some examples where generic servlet is used?
which method in doGet or doPost is use to send binary date to server
What are the different session tracking techniques?
What are the different ways we can maintain state between requests?
Can threads be used in Servelet?
Can we use threads in Servlets?
How servlet is created?
Hi frnds iam new to Java Kindy any one can provide or me Servlets Example code and can explain to me flow of servlets and as Jsp and Struts and provide to me some sample example on these 3 topic flow,code example,and tutorials,and related websites which i can refer....thanks in advance..........
Explain the architechure of a servlet?
What do you mean by web applications?
Can we override the ActionServlet?
3 Answers ArisGlobal, HCL, PPF,