Java Reference
In-Depth Information
The Servlet Interface
public abstract interface Servlet
The Servlet interface is implemented by all servlets either through direct implementation or
inheritance. It defines five methods, including the three life cycle methods, to be implemented
by all servlets.
The init() Method
public void init(ServletConfig config)
throws ServletException
The init() method, the first life cycle method, marks the beginning of a servlet's life. It is
called only when the servlet is first loaded, and it must execute successfully before the servlet
can service requests. The init() method should contain all initialization code for the servlet. It
returns no value.
init() has one parameter:
It throws this exception:
The getServletConfig() Method
public ServletConfig getServletConfig()
The getServletConfig() method returns the servlet's ServletConfig object, which contains
the servlet's startup configuration and initialization parameters. getServletConfig() has no
parameters and throws no exceptions.
It returns this value:
The service() Method
public void service(ServletRequest request,
ServletResponse response)
throws ServletException,
The service() method defines the servlet's entry point for servicing requests. It can be exe-
cuted only after the servlet's init() method has executed successfully. The service() method
is the life cycle method executed for every incoming request. It returns no value.
Search WWH ::

Custom Search