0% found this document useful (0 votes)
232 views7 pages

Servlet and JSP Life Cycle

The servlet lifecycle consists of init(), service(), and destroy() methods. The init() method initializes the servlet, service() handles requests and responses, and destroy() destroys variables and objects. The JSP lifecycle is similar but includes additional translation and compilation steps before init() and after service(). It translates JSP files to servlets, compiles them, then loads and initializes the servlet class.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
232 views7 pages

Servlet and JSP Life Cycle

The servlet lifecycle consists of init(), service(), and destroy() methods. The init() method initializes the servlet, service() handles requests and responses, and destroy() destroys variables and objects. The JSP lifecycle is similar but includes additional translation and compilation steps before init() and after service(). It translates JSP files to servlets, compiles them, then loads and initializes the servlet class.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Question :

Explain
Servlet and
JSP life cycle

Answers:

Servlet Lifecycle:
init() ->this initalizes the
servlets
initialization informationwith
the configuration
parameters.

service : here the business


logic starts. that is, all the
request and response
services goes here.

destroy() : once the process


is completed, it will be used
to destory all vairables and
objects used by servlets.

JSP lifecycle is somewhat


diff that servlet life cycle. It
includes four steps for the
same.
jspInit:works like servlet init
method.
jspTransleted: used to
translate the JSP into servlet
and in case of Tomcat
server,thats translated
servlets goes in work
directory.
_jspService: Its works like
servlet's service method.
jspDestory: same as servlets
destory method.

Life Cycle of JSP

1) init()
2) service()
3) destroy()

Posted by: Ghanshyam

Contact Ghanshyam

Life cycle of the SERVLETS:-

1)the class is loaded.


2)the constructor is
called(create object of that
class),
3)container then calls the
init() method that creates
the servletconfig and
servletcontext objects used
for accessing the init
parameter within the web
app.
4)container calls the
service() method by creating
the thread for each new
request.
5)after the service()
method the container calls
the destroy() method.

Life cycle of the JSP:-


1)create a file with .jsp
extension....that file is then
translated into.java file.
2)that file is then compiled
thereby creating the .class
file
3)that class is loaded.
4)then jspinit() method is
called.
5)then container calls the
jspservice() method
6)finally jspdestroy()
method is called.

Posted by: Manish Sahni

Contact Manish Sahni


Servlet Lifecycle:
init() ->this initalizes the
servlets
initialization informationwith
the configuration
parameters.

service : here the business


logic starts. that is, all the
request and response
services goes here.

destroy() : once the process


is completed, it will be used
to destory all vairables and
objects used by servlets.

JSP lifecycle is somewhat


diff that servlet life cycle. It
includes four steps for the
same.
jspInit:works like servlet init
method.
jspTransleted: used to
translate the JSP into servlet
and in case of Tomcat
server,thats translated
servlets goes in work
directory.
_jspService: Its works like
servlet's service method.
jspDestory: same as servlets
destory method.

Life Cycle of JSP

1) init()
2) service()
3) destroy()

Posted by: dhiraj kumar


srivastava

Contact dhiraj kumar


srivastava

<1> load the class


class.forName("servlet");
<2> run the default
constructor by cantainer
<3> create the Servlet
Config
<4> call the init()method
and pass the reference of
ServletConfig as parameter
<5> create the
ServletRequest and Servlet
Response
<6> class service()method
ans pass the reference of
request and respone as
parameter
<7> if again request for
same page then go step 5
<8> call destroy()method

Posted by: Sumer Singh

Contact Sumer Singh

Servlet Lifecycle
first the url is collected from
the user generates an http
request, this request is
mapped with the appropriate
servlet and loaded in the
address space of the server.
once the servlet is loaded
the following 3 phases
starts
1. init():
2.service()
3 destroys()

Jsp Life cycle


JSP engine does the
following 7 phases.
Page translation: -page is
parsed, and a java file which
is a servlet is created.
Page compilation: page is
compiled into a class file
Page loading : This class file
is loaded.
Create an instance :-
Instance of servlet is
created
jspInit() method is called
_jspService is called to
handle service calls
_jspDestroy is called to
destroy it when the servlet
is not required.

You might also like