VisualBuilder
  Home > Jsp > Tutorials > Servlet Execution Flow - Java Web Component Tutorial
Tell a friend
Link to us
Total Members
      Members: 84606
     
Sitemap Forum Chat
Home
Java Web Component Tutorial Home
1 . Basics to the web
2 . URI and URL
3 . Contents of Request and Response
4 . When a Servlet is invoked
5 . Servlet Execution Flow
6 . Example Time!
7 . Servlet Execution Flow
8 . Keep Coming Back for more updates.
 
Jsp Group Home
Jsp Discussion (71)
Jsp Members (18673)
Jsp Resources
Jsp Source Code (172)
Jsp Articles (3)
Jsp Blogs
Jsp Jobs
Jsp Components (10)
Jsp Books
Jsp Websites (13)
Jsp News (12)
Jsp Q & A (79)
- Jsp Ask Question
- Jsp Questions
- Jsp Unanswered Questions
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (432 )
Source Code (3217 )
Articles (11 )
Components (1589 )
News (880 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise


Jsp webcomponent Tutorial
 Servlet Execution Flow
  << Prev: Example Time! Next: Keep Coming Back for more updates. >>

Servlet Execution Flow
Servlet Life cycle

In the figure 1 we saw the activities a container needed to perform when a Servlet gets called. Now we will see what activities a container has to do in order to make a servlet available. And that is the mechanism of a Servlet life cycle.

 

1. Loading.

            Container first creates an instance of a servlet by using Class.forName(ServletName).newInstance()

      That is the reason why we do not have any constructor for a servlet. The container does the job for us. This process is also called the instantiation. The next question which will come to your mind is how   does the container comes to know which servlets to load and where to find them. The answer is simple. For each web apps there is a deployment descriptor file associated with the web apps,and that is called web.xml. We will  study details about web.xml shortly,but just keep in mind that web.xml has got an entry for the servlets associated with that web application. When the container starts,one of the activities done is to parse the web.xml and read the class names of the servlet and load them one by one. The servlet is loaded.

 

2. Initialising

The container initialises a servlet by calling init(ServletConfig) of the Servlet. The ServletConfig object contains all the initialising parameter read from web.xml,for this Servlet. The init() method is called only once by the container for a servlet instance. This makes sense because there is no point in initialising a servlet instance again and again. The servlet is now initialised.

 

3. Servicing

Servlet is now in a ready state for servicing a client request. Any request received from the client is despatched to the service() method of the servlet instance. We have already seen in Figure 1 how a request goes to the service method. A servlet instance is now said to be in the servicing stage. When a service() method is called a Servlet is in Servicing stage.

           

4. Destroy

A servlet container can destroy a servlet instance by calling the destroy() method . We should write cleanup scripts in here,like closing data base connections,file handlers etc. Container will call this method only once when once all threads within the servlet's service method have exited

 

5. Unloading

Once the servlet instance is destroyed the container may garbage collect it. The servlet is said to be unloaded.

 


lifecycle

 

One important thing you must keep in mind is that a container creates one and only one instance of a servlet,unless the servlet implements SingleThreadModel. Multiple concurrent request are handled by container through a pool of threads.

 

In the next part we will study more about the deployment descriptor (web.xml),ServletConfig,ServletContext,and more about ServletRequest and ServletResponce.


  << Prev: Example Time! Next: Keep Coming Back for more updates. >>
Jsp Webcomponent Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
LINKS
online fax server
Video Surveillance
Exchange Hosting
Gift to Pakistan
 
ADVERTISEMENT
 
PARTNER LIST

More
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising