Explain the underlying method of Servlet interface

Explain the underlying method of Servlet interface.

1. init()
2. service()
3. destroy()
4. getServletConfig()
5. getServletInfo()

1. init() :

- This method initializes the servlet.

- It invokes only once and automatically invoked by the servlet engine / container.

- This method is used and guarantees the actions that are to be performed before the service() method is invoked.

- This is an overloaded method with no parameter and one ServletConfig object.

- Incase of a fatal error during initialization, the init() method throws UnavailableException object.

2. service() :

- To carry a single request sent by a client, this method is used.

- This method implements / performs the paradigm of request and response.

- The request object contains the information of the service request including the client sent parameters.

- The response object is used to send the response to the client.

- The quality of handling these two methods rely on the underlying network environment.

3. destroy() :

- Invoked just before the stopping the operations by the servlet.

- It performs the resources cleaning process such memory, files, threads removal and ensures the persistence state is synchronized by the servlet’s current in-memory state.

- The destroy() method invoked only once before the unloading the servlet.

4. getServletConfig() :

- This method is used to return the servlet config object.

- This object contains the initialization parameters and startup configuration for this servlet.

- This method returns the ServletConfig object to init() method and the init() method will store this object in order to return ServletConfig object if needed.

5. getServletInfo() :

- This method returns a string that contains the information of the servlet such as version, copyright, author.

- This information is used as administrative tool and be displayed by the servlet engine.

- It returns this information in plain string form, as the information is servlet engine specific.
What is GenericServlet class?
This class implements Servlet and ServletConfig interfaces. This class can be extended by a servlet.....
What is HTTPServlet class?
The HTTPServlet class provides an abstract class that is to be sub classed which is suitable for a web site......
What is Servlet context?
Servlet context is created by the container and can be viewed as a shared memory resource for all the servlets for a web application.....
Post your comment