JSP Life Cycle – explain.

Last modified on July 25th, 2014 by Joe.

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.

Comments on "JSP Life Cycle – explain."

  1. nirav jain says:

    figure for jsp life cycle is not given here..

  2. Raj says:

    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 says:

    its really nice ………

  4. vidhya says:

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

  5. sonya says:

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

  6. Ammu says:

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

  7. Ammu says:

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

  8. ayush says:

    thanks bro…..it’s really helpful

  9. Jinesh says:

    Great work

    I understood the JSp lifecycle fully

  10. Anonymous says:

    Good

  11. rohan says:

    very very simple and nice site thanks admin

  12. hassan syed says:

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

  13. Anonymous says:

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

  14. mohan says:

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

  15. Anonymous says:

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

  16. Shilpa says:

    Lifecycle explaination is Excellent

  17. Anonymous says:

    simple and understandable………! nice work.

  18. Nagaraj says:

    excellent.

  19. guru says:

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

  20. radha says:

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

  21. Anonymous says:

    Good one

  22. Anonymous says:

    good example for the life cycle

  23. chetnath says:

    very easy and nice example

  24. Javahere.com says:

    Excellent post on jsp life cycle ! thanks a lot!

  25. ashok chauhan says:

    exellent explenetion

  26. Madhuparna Mukherjee says:

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

  27. ashok chauhan says:

    very good exellent explenetion

  28. Joe says:

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

  29. charu says:

    excellent

  30. anonymous says:

    so brief but fair enough, thanx

  31. Niranjan says:

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

  32. dinesh mca says:

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

  33. amit says:

    Perfect Job Thanks Man.

  34. gourav says:

    easy and compact to answer in interviews

  35. Mahammad Seeraz says:

    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

  36. ashok says:

    EXCELENT info on life cycle

  37. yamini says:

    fantastic!!!mind blowin!!!

  38. shashibushan says:

    Thanks, t u r explanation about the jsp Life Cycle

    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 ?

  39. Sp says:

    that game was called paratrooper

  40. Joe says:

    Thanks Sp, I too figured it out lately.

  41. AJAY DALVI says:

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

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

  42. Aman says:

    Really small but efficient material for jsp .

  43. santosh says:

    Thanks! It was helpful,.

  44. swathika says:

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

  45. sathya says:

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

  46. Thamayanthi says:

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

  47. kiran says:

    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 says:

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

  49. Sandeep says:

    Thanks t’s very fantastic

  50. Srikanth S says:

    Good one Jeo…Neatly explained

  51. Raghuram says:

    The content is very useful, and clearly explained.

    Raghuram

  52. sudhakar says:

    Very good explanation ::

  53. narinder says:

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

  54. Premsathish says:

    thank! u for the info.

  55. Anonymous says:

    Good!

  56. Anonymous says:

    ok excellent

  57. rama Devi says:

    i am satisfied

  58. Raj yadav says:

    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

  59. Raj yadav says:

    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.

  60. Atique says:

    Really fine work but now I have switched to .Net

  61. Atique says:

    Every jsp page make a related servlet and servlet gets executed

  62. Praveen Kumar N says:

    very good.nice attempt:)

  63. Nithin says:

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

  64. Apurv says:

    Thanks and that was a gud one.

Comments are closed for "JSP Life Cycle – explain.".