Mostly a Servlet is having 3 major stages.
- Initialization—-init() method
- Destruction—-Destroy() method
The Signature is —
it takes the ServletConfig object as a parameter and pass it to the super init method.
So the structure of a init method looks like—
The important aspect of this signature is that a init method can throw an exception ServletException.When it occures??? If the init method could not initializes all the required resources that will will be used during it’s life time.
As picture depicts, once the init method is called , the second step is to call Service method. So Service method can not be called if the init method is not called. This methods actually talk to client ..i mean this method takes care of the request and response. We generally do not implement this method but if our servlet class is extended to GenericServlet then we need to implement that.Service method support HTTP /1.1 and above.
The method looks like-