ABC Article Directory banner displaying blue butterfly logo. Click to go directly to the main Homepage
Your Ad Here

Home | Computers | Programming

Add This Social Bookmark Button


animated blue butterfly symbol for the ABC Article Directory

Introduction To Java Servlets.


By: daringtakers Click author's name for more of his/her articles

A servlet is a Java technology based web component, managed by a container, that
generates dynamic content.

A servlet can be considered as a tiny Java program which processes user request and generates dynamic content.

There are many other alternatives like php, asp .net or CGI, for developing dynamic web sites. benefit of using servlets
over other technologies is servlets are developed in Java, so it comes with all benefits of Java language and it
is platform independent.

Following are the some advantages of using servlets.

(1) They are generally much faster than CGI scripts.
(2) They use a standard API that is supported by many web servers.
(3) They have all the advantages of the Java programming language, including
ease of development and platform independence.
(4) They can access the large set of APIs available for the Java platform.

What is a Servlet Container?
Servlet container is a runtime environment, which implements servlet API and manages life cycle of servlet components.
Container is responsible for instantiating, invoking, and destroying servlet components.
One example of container is Apache Tomcat which is an opensource container.

Servlet Life Cycle :
A servlet is managed through a well defined life cycle which defines how it is loaded,
instantiated and initialized, handles requests from clients, and how it is taken out of
service.

The servlet life cycle is consist of following phases.

(1) Instantiation
During this phase container creates a new instance of servlet. this is the first phase of servlet life cycle.

(2) Initialization
After the servlet object is instantiated, the container initializes the servlet before
it can handle requests from clients. during this phase container calls the init() method of servlet.
This is the second phase of servlet life cycle.

(3) Request Handling
Actual request processing and response generation occurs during this phase.
Container calls service() method of servlet component and passes ServletRequest and ServletResponse objects as parameter.

(4) Destroy
This is the last phase of servlet life cycle. during this phase container calls destroy() method of servlet component.
After this phase servlet is removed from service. this happens when server is shutting down, or server wants to free some memory.

All of this life cycle methods are defined in Servlet interface.

following methods are defined in Servlet interface

public void init(ServletConfig config)
public ServletConfig getServletConfig()
public void service(ServletRequest req,ServletResponse res)
public void destroy()

Current version of servlet specification is 2.5
New version of servlet specification is 3.0 which currently under development at java community process (JCP)

Article Source: ABC Article Directory



About The Author: More articles and tutorials can be found here Java articles and tutorials



Bookmark and Share eMail This Article to Friends

Please Rate this Article


# of Ratings = 1 | Rating = 5/5



RSS feeds on demand

Copyright ABC Article Directory All rights protected. Script Services by: Sustainable Website Design
Use of our free service is protected by our Privacy Policy and Terms of Service Contact Us
Creative Commons License
This work is licensed under a Creative Commons Attribution-No Derivative Works 3.0 Unported License.

Wind Powered Hosting

Powered by Article Dashboard