Monthly Archives: April 2013
What is web.xml?
The web.xml is a java web Application Deployment Descriptor(i.e DD) file.
This document will describe the application i.e all the Servlets and any other configuration for this application deploying into the server.
What happens if we call destroy() method from service()? That is ,is the container will remove the servlet making it unavailable?
Nothing,just the destroy() method logic will execute and clear the container will not remove the Servlet for this call.
Can we call destroy() method from service() method?
Yes,we can call.
When will container destroy the Servlet?
– Stop all the requests to this Servlet.
– Wait till the existing request to this Servlet get complete.
– Call the destroy() mehod of the Servlet After this the Servlet is no more there in the Container.
The Servlet is destroyed by the container following the above process only when the application is undeployed.
Can we write initialization logic in Constructor ?
Yes,but into no-argument Constructor. However in the Constructor we are not available with the ServletConfig.
It is recommonded by conversion to write the initialization in init() method compared to Constructor.
What are the lifecycle methods of Servlet?
The following 3 methods are the Servlet lifecycle Methods
1. public void init(ServletConfig config)
throws ServletException
2. public void service(ServletRequest req,
ServletResponse res)
throws ServletException,
java.io.IOException
3. public void destroy()
By using which 2 Packages we can implement Servlet?
-
javax.servlet
-
javax.servlet.http