Servlet
Servlet is an API provided by 'sun microsystem' to facilitate development of dynamic web applications.
The term 'servlet ' is used in two different context; in the broader context it represent an API and in the narrow context it represents an interface define using the API.
Javax.servlet package added some packages contents classes
and interfaces of servlet API, at the core of the servlet API is an interface named ‘Servlet’ (javax.servlet.Servlet)
this interface provides lifecycle methods of a servlet.
Lifecycle methods of Servlet :-
1.
init():- This method is invoke only ones just
after a servlet object is created. It is used by the application developers to
perform initialization
public void init(ServletConfig config) throws
ServletException;
It is used by the server to provide the
reference of the ServletConfig object to the servlet.
ServletConfig is an interface of servlet
API implementation of it is provided by vendors.
2.
Service():- This method is invoke each time a
request for the servlet is receive. It is used by the servlet to process request and generate the html
contents.
public void service(ServletRequest request, ServletResponse
response)throws ServletException, IOException;
In this method references of objects of
type Servletrequest and ServletResponse are provided by the server these
objects act as interface between the server and the servlet that is server
provides request data to the servlet
through ServletRequest object and server
receives response from the servlet object through ServletResponse
object.
3.
destroy():- This method is invoke only onse
just before the servlet is unloaded . It is used to perform cleanup operations
public void destroy();
Non Lifecycle methods of Servlet Interface:-
1.
getServletConfig():- This method is used to
obtain the reference of ‘ServletConfig’ object
of a servlet.
public ServletConfig getServletConfig();
2.
getServletInfo():- This method is used to
obtain the description of the servlet.
public String getServletInfo();
Note: Total five
methods are available in Servlet interface – three are lifecycle and two are
non lifecycle methods.






nice one its really helpfull
ReplyDelete