JSP Life Cycle – explain.

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.

This JSP tutorial was added on 05/05/2008.

«

»

Comments on “JSP Life Cycle – explain.”

  1. nirav jain

    figure for jsp life cycle is not given here..

  2. Raj

    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.

  3. Julfiur Rahman

    its really nice ………

  4. vidhya

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

  5. sonya

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

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

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

  8. ayush

    thanks bro…..it’s really helpful

  9. Jinesh

    Great work

    I understood the JSp lifecycle fully

  10. Anonymous

    Good

  11. rohan

    very very simple and nice site thanks admin

  12. hassan syed

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

  13. Anonymous

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

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

  15. Anonymous

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

  16. Shilpa

    Lifecycle explaination is Excellent

  17. Anonymous

    simple and understandable………! nice work.

  18. Nagaraj

    excellent.

  19. guru

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

  20. radha

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

  21. Anonymous

    Good one

  22. Anonymous

    good example for the life cycle

  23. chetnath

    very easy and nice example

  24. Javahere.com

    Excellent post on jsp life cycle ! thanks a lot!

  25. Madhuparna Mukherjee

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

  26. ashok chauhan

    very good exellent explenetion

  27. Joe

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

  28. charu

    excellent

  29. anonymous

    so brief but fair enough, thanx

  30. Niranjan

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

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

  32. Perfect Job Thanks Man.

  33. gourav

    easy and compact to answer in interviews

  34. Mahammad Seeraz

    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

  35. ashok

    EXCELENT info on life cycle

  36. yamini

    fantastic!!!mind blowin!!!

  37. shashibushan

    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 ?

  38. Sp

    that game was called paratrooper

  39. Joe

    Thanks Sp, I too figured it out lately.

  40. AJAY DALVI

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

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

  41. Really small but efficient material for jsp .

  42. santosh

    Thanks! It was helpful,.

  43. sathya

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

  44. Thamayanthi

    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……

  45. Thamayanthi

    my mail:ramya.cool88@gmail.com

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

  47. kiran

    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.

  48. kothagattu srinivas

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

  49. Sandeep

    Thanks t’s very fantastic

  50. Srikanth S

    Good one Jeo…Neatly explained

  51. Raghuram

    The content is very useful, and clearly explained.

    Raghuram

  52. sudhakar

    Very good explanation ::

  53. narinder

    Thanks buddy , hope it remains in my brain till interview :-)

  54. Premsathish

    thank! u for the info.

  55. Anonymous

    Good!

  56. Anonymous

    ok excellent

  57. rama Devi

    i am satisfied

  58. Raj yadav

    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.

  59. Thanks buddy , hope it remains in my brain till interview :-)& I Hope you got lot of info:about jsp search now ok best of luck…………………………
    RAJ YADAV

  60. Atique

    Really fine work but now I have switched to .Net

  61. Atique

    Every jsp page make a related servlet and servlet gets executed

  62. Praveen Kumar N

    very good.nice attempt:)

  63. Nithin

    thankx bro.. you helped me to pass exam..

  64. Apurv

    Thanks and that was a gud one.

Comments are closed.