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.

previous post: When does the finally clause in java exception block never executes?

next post: Difference between _jspService() and other life cycle methods.

65 comments on “JSP Life Cycle – explain.

  1. figure for jsp life cycle is not given here..

  2. 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. its really nice ………

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

  5. 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. thanks bro…..it’s really helpful

  9. Great work

    I understood the JSp lifecycle fully

  10. very very simple and nice site thanks admin

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

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

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

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

  15. Lifecycle explaination is Excellent

  16. simple and understandable………! nice work.

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

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

  19. good example for the life cycle

  20. very easy and nice example

  21. Excellent post on jsp life cycle ! thanks a lot!

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

  23. very good exellent explenetion

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

  25. so brief but fair enough, thanx

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

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

  28. easy and compact to answer in interviews

  29. 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

  30. EXCELENT info on life cycle

  31. fantastic!!!mind blowin!!!

  32. 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 ?

  33. that game was called paratrooper

  34. Thanks Sp, I too figured it out lately.

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

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

  36. Really small but efficient material for jsp .

  37. Thanks! It was helpful,.

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

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

  40. my mail:ramya.cool88@gmail.com

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

  42. 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.

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

  44. Thanks t’s very fantastic

  45. Good one Jeo…Neatly explained

  46. The content is very useful, and clearly explained.

    Raghuram

  47. Very good explanation ::

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

  49. thank! u for the info.

  50. 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.

  51. 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

  52. Really fine work but now I have switched to .Net

  53. Every jsp page make a related servlet and servlet gets executed

  54. very good.nice attempt:)

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

  56. Thanks and that was a gud one.