Wish to have some nice time? Check out what I'm reading online!

JSP Life Cycle – explain.

May 5th, 2008

JSP’s life cycle can be grouped into following phases.

1. JSP Page Translation:

A java servlet file is generated from the JSP source file. This is the first step in its tedious multiple phase life cycle. In the translation phase, the container validates the syntactic correctness of the JSP pages and tag files. The container interprets the standard directives and actions, and the custom actions referencing tag libraries used in the page.

2. JSP Page Compilation:

The generated java servlet file is compiled into a java servlet class.

Note: The translation of a JSP source page into its implementation class can happen at any time between initial deployment of the JSP page into the JSP container and the receipt and processing of a client request for the target JSP page.

3. Class Loading:

The java servlet class that was compiled from the JSP source is loaded into the container.

4. Execution phase:

In the execution phase the container manages one or more instances of this class in response to requests and other events.
The interface JspPage contains jspInit() and jspDestroy(). The JSP specification has provided a special interface HttpJspPage for JSP pages serving HTTP requests and this interface contains _jspService().

5. Initialization:

jspInit() method is called immediately after the instance was created. It is called only once during JSP life cycle.

6. _jspService() execution:

This method is called for every request of this JSP during its life cycle. This is where it serves the purpose of creation. Oops! it has to pass through all the above steps to reach this phase. It passes the request and the response objects. _jspService() cannot be overridden.

7. jspDestroy() execution:

This method is called when this JSP is destroyed. With this call the servlet serves its purpose and submits itself to heaven (garbage collection). This is the end of jsp life cycle.

jspInit(), _jspService() and jspDestroy() are called the life cycle methods of the JSP.

figure for jsp life cycle is not given here..

nirav jain on November 14th, 2009 5:08 pm

Excellent man, you really helped me.
thank you.
Keep it UP.
one thing I would like to Suggest you,
that you can Show JSP life cycle Diagramatically.

Raj on November 22nd, 2009 9:07 pm

its really nice ………

Julfiur Rahman on December 14th, 2009 11:53 am

it s very useful for knowing abt jsp..
thank u

vidhya on December 14th, 2009 9:30 pm

thanx
it really helped me a lot in understanding JSP and its life cycle. keep it up

sonya on December 24th, 2009 5:57 am

Thanks for helping me..
Its clearly undersandale for beginners…..

Ammu on December 29th, 2009 9:06 am

Thanks for helping me..
Its clearly undersandable for beginners…..

Ammu on December 29th, 2009 9:11 am

thanks bro…..it’s really helpful

ayush on January 8th, 2010 12:18 pm

Great work

I understood the JSp lifecycle fully

Jinesh on January 21st, 2010 7:32 am

Good

Anonymous on January 22nd, 2010 7:15 am

very very simple and nice site thanks admin

rohan on February 7th, 2010 2:00 am

Its the best page i have ever visited about jsp life cycle.

hassan syed on February 16th, 2010 10:16 am

best explanation for jsp life cycle in any java blog i have seen…..

Anonymous on February 16th, 2010 2:02 pm

thanks for the definition on jsp life cycle. it’very useful.

mohan on February 25th, 2010 9:06 am

Jsp Lifecycle with a neat sketch:
Check out the other information for this topic in your book.

Anonymous on March 3rd, 2010 6:15 pm

Lifecycle explaination is Excellent

Shilpa on March 23rd, 2010 10:42 pm

simple and understandable………! nice work.

Anonymous on March 31st, 2010 4:08 pm

excellent.

Nagaraj on April 1st, 2010 6:16 am

thank you very much for definition – a neat sketch for jsp life cycle too is suggested.

guru on April 2nd, 2010 12:19 pm

the contents are clearly presented in this site.good work !

radha on April 9th, 2010 9:16 am

Good one

Anonymous on April 13th, 2010 6:31 am

good example for the life cycle

Anonymous on April 15th, 2010 11:05 am

very easy and nice example

chetnath on April 18th, 2010 3:42 pm

Excellent post on jsp life cycle ! thanks a lot!

Javahere.com on April 25th, 2010 9:34 am

Good explanation.Figure needed to explain the jsp life cycle completely.

Madhuparna Mukherjee on April 27th, 2010 6:20 am

very good exellent explenetion

ashok chauhan on April 27th, 2010 6:47 am

exellent explenetion

ashok chauhan on April 27th, 2010 6:48 am

I have been consistently asked for a diagram to explain JSP life cycle. Quite soon I will update it. Thanks guys.

Joe on April 27th, 2010 7:29 pm

excellent

charu on May 3rd, 2010 3:14 am

so brief but fair enough, thanx

anonymous on May 9th, 2010 2:33 pm

Thanx for t clarity on life cycle phases. It was good explanation.

Niranjan on May 14th, 2010 9:32 am

thank u so much for explaiing the jsp lifecycle ya,,,,,,,,,,,,,,,,,,,,,,,,,,
by
dinesh mca
ramanathapurm(district)

dinesh mca on May 21st, 2010 9:05 am

Perfect Job Thanks Man.

amit on May 24th, 2010 7:01 am

easy and compact to answer in interviews

gourav on May 24th, 2010 5:57 pm

can any body explain point no 7 above

7. jspDestroy() execution:

This method is called when this JSP is destroyed.

whaether this method is called to destroy jsp/when jsp is destroyed.
thnx in advance

Mahammad Seeraz on May 28th, 2010 5:41 am

EXCELENT info on life cycle

ashok on June 4th, 2010 3:06 am

fantastic!!!mind blowin!!!

yamini on June 7th, 2010 6:29 am

Thanks, t u r explanation about the jsp Life Cycle

k, i have one dought pls replay to my mail

my mail :- shashibushan2008@gmail.com

In the WebContainer calls init() and destroy() methods call only once and Service() method calls zero or more than no. of times in SERVLET life cycle.

like in this way

jspInit() and _jspDestroy() methods call once or more than once?
jspService() method calls Zero or more than no. of time ?

shashibushan on June 13th, 2010 5:20 pm

that game was called paratrooper

Sp on June 16th, 2010 7:11 pm

Thanks Sp, I too figured it out lately.

Joe on June 17th, 2010 8:11 am

thank….
though i did a project using jsp ,still ni d`t know this basic

yes it help me lot……..keep it up..

AJAY DALVI on June 22nd, 2010 11:32 am

Really small but efficient material for jsp .

Aman on June 23rd, 2010 7:10 am

Thanks! It was helpful,.

santosh on July 1st, 2010 9:40 am

life cycle flow is marvelous..thanks v want more infor about jsp..if anybody knows plz send to my mail id…..

sathya on July 6th, 2010 4:13 am

Really It’s very useful for me….I’m gng to do project in jsp so plzzz give more inf about jsp and help for my project…

waiting for answer……

Thamayanthi on July 6th, 2010 4:17 am

my mail:ramya.cool88@gmail.com

Thamayanthi on July 6th, 2010 4:18 am

It’s very fantastic ….thanks pa….I need brief about jsp..send to my mail quickly..

swathika on July 6th, 2010 4:44 am

please tell me
if jsp which was called first time has been destroyed by using jspdestoy()method.Suppose if the server gets same jsp request what would happen second time whether it needs to execute all the lifecycle methods or only jspService().if it execute jspService() how it will be available because jsp already destroyed .

Thanks in advance.

kiran on July 14th, 2010 6:09 am

thank you very much.this one help more to me.but here not given the daigram.

kothagattu srinivas on July 28th, 2010 5:28 pm





hidden and gravatar enabled.