REGISTER FREE to Receive Instant Job

Monday, 10 November 2014

Servlet Web Applications and Life cycle methods of Servlet

Servlet Technology and Life cycle methods of Servlet:- 

  • Servlet is a technology for developing Web Applications in Java.
  • Apart from technology, Servlet term is also used to describe those programs which are developed using this technology.
  • As an Application Component, Servlet represents such programs which are executed within a Web Server and generates dynamic html.
  • Before Servlets, Dynamic Web Applications used to be developed using CGI.

CGI is a protocol that defines standard mode of communication between web server and program. In case of CGI based application, programs were written in C, C++ or perl. These programs were called CGI scripts.

CGI based applications had following two problems-

  • CGI scripts were platform dependent.
  • CGI scripts were executed as processes which use to create lot of overhead.

Servlet as a technology of web development solved both the problems associated with CGI.

  • javax.servlet package & its sub-packages provide classes & interfaces that facilitate development of Web Applications.
  • At the core of Servlet API, is an interface javax.servlet.Servlet. This interface defines life cycle methods of Servlets.

Life cycle methods of Servlet-

  • init() method is invoked only once just after a Servlet object is created. It is used by the server to provide the reference of an object of type ServletConfig to the servlet. ServletConfig is an interface of Servlet API, implementation of which is provided by Server Vendor.


public void init(ServletConfig config);


  • service() method is invoked by the server each time a request for the servlet is received. It is used by the Application Developer for processing request.


public void service (ServletRequest request, ServletResponse response) throws ServletException, IOException;

In this method Web Server provides the reference of objects of type ServletRequest & ServletResponse. These are interfaces of Servlet API which are implemented by Server Vendor.
These two objects act as interface between WebServer and Servlet.



  • destroy() method is invoked only once just before a servlet is unloaded.

public void destroy();

Non-life cycle methods of servlet-

  • getServletConfig() method is used to obtain the reference of ServletConfig object from the servlet.

public ServletConfig getServletConfig();

  • getServletInfo() method is used by the Application Developer to describe a servlet.

public String getServletInfo();



2 comments:

  1. The blog or and best that is extremely useful to keep I can share the ideas
    of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
    tanki online | 2048 game |
    tanki online game

    ReplyDelete

Popular Posts

Powered by Blogger.

About Me

My photo

JobsAcid is a 'job search engine' to provide finding a job on the internet easier for the user. It has designed as huge selection of job offerings on the same search engine.