0% found this document useful (0 votes)
38 views5 pages

What Are The Phases of Servlet Life Cycle?: Web Technology

The document discusses the servlet API life cycle methods, phases of the servlet life cycle, and differences between servlets and JSPs. It also explains the creation, instantiation, and usage of Java beans objects. The servlet life cycle contains 5 phases - loading the servlet class, creating an instance, calling the init() method, calling the service() method for each request, and calling the destroy() method. The init(), service(), and destroy() methods are central to the servlet life cycle. Servlets and JSPs are both used to create dynamic web content, but servlets are compiled into Java classes while JSPs are compiled into servlets. Java beans follow conventions like having a

Uploaded by

Repu Daman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views5 pages

What Are The Phases of Servlet Life Cycle?: Web Technology

The document discusses the servlet API life cycle methods, phases of the servlet life cycle, and differences between servlets and JSPs. It also explains the creation, instantiation, and usage of Java beans objects. The servlet life cycle contains 5 phases - loading the servlet class, creating an instance, calling the init() method, calling the service() method for each request, and calling the destroy() method. The init(), service(), and destroy() methods are central to the servlet life cycle. Servlets and JSPs are both used to create dynamic web content, but servlets are compiled into Java classes while JSPs are compiled into servlets. Java beans follow conventions like having a

Uploaded by

Repu Daman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Web Technology

Question 1. Explain the servlet API Life Cycle methods in brief

Three methods are central to the life cycle of a servlet. These are init(),service() and
destroy().They are implemented by every servlet and are invoked at a specific time by the
server.

What are the phases of Servlet life cycle?


The servlet life cycle contains five phases:

1) load a servlet class -

The class Classloader is responsible to load servlet class.ClassLoader object is designed to


load a class just once. It is loaded, when the first request for the servlet is received by the web
container.

2) Servlet instance is created -

At the time code for a servlet is loaded, the server creates a single instance. That single
instance handles every request made of the servlet. The servlet object is created once in the
entire servlet life cycle.

3) init() method -

init() method is called after creating the servlet instance. It is called only once in the entire
lifecycle. It is used to initialize the servlet.Init() is guaranteed to be called and completed
before the servlet handles its first request. During init() method a servlet may want to read its
initialization (init) parameter.

4) service() method -

Service() method is called every time when a request for a servlet is received.
Service() method is used to handle requests as appropriate for the servlet.The service()
method accepts 2 parameters: a request object and a response object.
It overrides doGet() and doPost() method.
doGet() method — doGet() method is used to handle the get request.

doPost() method — doPost() method is used to handle the Post request.

Servlet Life Cycle

5) Destroy() method -

This method is called only once in the entire life cycle of a servlet. The servlet calls the
destroy() method after the servlet has been taken out of service and all pending requests have
completed or timed out.
Question 2 : Discuss the basic differences between Servlet and JSP
Question 3: Explain in Detail the creation, instantiation and usage of
java beans objects

A JavaBean is a specially constructed Java class written in the Java and


coded according to the JavaBeans API specifications.
Following are the unique characteristics that distinguish a JavaBean from
other Java classes −
 It provides a default, no-argument constructor.
 It should be serializable and that which can implement
the Serializable interface.
 It may have a number of properties which can be read or written.
 It may have a number of "getter" and "setter" methods for the
properties.

JavaBeans Properties
 A JavaBean property is a named attribute that can be accessed by
the user of the object. The attribute can be of any Java data type,
including the classes that you define.
 A JavaBean property may be read, write, read only, or write only.
JavaBean properties are accessed through two methods in the
JavaBean's implementation class −

S.No. Method & Description

getPropertyName()
1
For example, if property name is firstName, your method name
would be getFirstName() to read that property. This method is
called accessor.

setPropertyName()

2 For example, if property name is firstName, your method name


would be setFirstName() to write that property. This method is
called mutator.

 A read-only attribute will have only a getPropertyName() method,


and a write-only attribute will have only
a setPropertyName() method.

You might also like