Servlet API

public interface Servlet

So you can see that Servlet is an interface, this interface contains all the method that is used to implement servlet.
the all method defines in servlet is must to be implemented in all servlet class. 

To implement this servlet the servlet class must have to be extend
  javax.servlet.GenericServlet or
  javax.servlet.http.HttpServlet.


this interface have method to initialize the servlet, to service request and all other related tasks.
these are also known as the life cycle method of the servlet.

  • The servlet is constructed, then the init() method is called to initialize the servlet.
  • if the client raises any request service() method will handle that.
  • if the servlet is out of service, destroy() method will occur to destroy the servlet, then the Garbage collector performs the task and finalized.
there is two more methods in this interface that is used to return basic info about version, copyright, etc.
the methods are
getServletConfig()
getServletInfo().

Methods
  1. void init(ServletConfig config) throw ServletException
  2. void service(ServletRequest request, ServletResponse response) throws ServletException,java.io.exception
  3. getServletConfig()
  4. String getServletInfo()
  5. destroy()
Method Details

1- void init(ServletConfig config) throw ServletException


the init() is called by the servlet container to notify a servlet that the servlet is placed successfully in the service method.
before the servlet receives any request, the init method must be completed.

2- void service(ServletRequest request, ServletResponse response) throws ServletException,java.io.exception

When the init method completed successfully service method is called to allow the servlet to respond to a request.
request- the ServletRequest objects used for client request
response- the ServletResponse objects used for servlet response

3- getServletConfig()

ServletConfig object contains initialization parameters for a servlet.

4- String getServletInfo()

this method return the information about the servlet.

5- destroy()
when the servlet is taken out of service servlet container indicate this method to execute.

No comments:

Post a Comment