Servlet Interface

Advertisements

Prev Tutorial Next Tutorial

Servlet Interface

It is an interface to define a Servlet, the implementation class of this Servlet should override all methods of Servlet interface.
Servlet interface needs to be implemented for creating any Servlet (either directly or indirectly). It provides 3 life cycle methods that are used to initialize the Servlet, to service the requests, and to destroy the Servlet and 2 non-life cycle methods.

Methods of Servlet interface

MethodDescription
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.

Example of servlet by implementing Servlet interface

Syntax

public class myServlet implements server
{
....
}
public void destroy()
{
.....
}
public void init(ServletConfig se)
{
.....
}
public ServletConfig getServletConfig()
{
.....
}
public String getServiceInfo()
{
....
}
public void service(ServletRequest req, ServletResponse resp)throws IOException, ServletException
{
....
}

Prev Tutorial Next Tutorial

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements