1.6K
Servlet Interface
In this article, you’ll learn about Servlet Interface. When the Servlet is deployed in the server the Servlet container creates life cycle of the Servlet. The central abstraction in the Servlet API is the Servlet interface, all the Servlets have to implement this interface either directly or by extending a class such as GenericServlet, HttpServlet.
Following are the different methods of servlet interface.
Method | Description |
---|---|
public void init(ServletConfig config) | initializes the servlet. It is the life cycle method of servlet and invoked by the web container only once. |
public void service(ServletRequest request,ServletResponse response) | provides response for the incoming request. It is invoked at each request by the web container. |
public void destroy() | is invoked only once and indicates that servlet is being destroyed. |
public ServletConfig getServletConfig() | returns the object of ServletConfig. |
public String getServletInfo() | returns information about servlet such as writer, copyright, version etc. |