Monday, October 1, 2012

Servlet Life Cycle

Servlet Life Cycle


The following is a nice tutorial on Servlet Life Cycle.
http://tutorials.jenkov.com/java-servlets/servlet-life-cycle.html

By default the servlet is not loaded until the first request is received for it. You can force the container to load the servlet when the container starts up though.

A Servlet is part of a Java web application. A Servlet container may run multiple web applications at the same time, each having multiple servlets running inside. Here is an llustration of that:

The browser sends an HTTP request to the Java web server. The web server checks if the request is for a servlet. If it is, the servlet container is passed the request. The servlet container will then find out which servlet the request is for, and activate that servlet. The servlet is activated by calling the Servlet.service() method.


The servlet life cycle is managed by the servlet container. The life cycle contains the following steps:

1.Load Servlet Class.
2.Create Instance of Servlet.
3.Call the servlets init() method.
4.Call the servlets service() method.
5.Call the servlets destroy() method.

No comments:

Post a Comment