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

    Thanks and that was a gud one.

  2. Nithin says:

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

  3. Praveen Kumar N says:

    very good.nice attempt:)

  4. Atique says:

    Every jsp page make a related servlet and servlet gets executed

  5. Atique says:

    Really fine work but now I have switched to .Net

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

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

  8. rama Devi says:

    i am satisfied

  9. Anonymous says:

    ok excellent

  10. Anonymous says:

    Good!

  11. Premsathish says:

    thank! u for the info.

  12. narinder says:

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

  13. sudhakar says:

    Very good explanation ::

  14. Raghuram says:

    The content is very useful, and clearly explained.

    Raghuram

  15. Srikanth S says:

    Good one Jeo…Neatly explained

  16. Sandeep says:

    Thanks t’s very fantastic

  17. kothagattu srinivas says:

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

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

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

  20. sathya says:

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

  21. swathika says:

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

  22. santosh says:

    Thanks! It was helpful,.

  23. Aman says:

    Really small but efficient material for jsp .

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

  25. Joe says:

    Thanks Sp, I too figured it out lately.

  26. Sp says:

    that game was called paratrooper

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

  28. yamini says:

    fantastic!!!mind blowin!!!

  29. ashok says:

    EXCELENT info on life cycle

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

  31. gourav says:

    easy and compact to answer in interviews

  32. amit says:

    Perfect Job Thanks Man.

  33. dinesh mca says:

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

  34. Niranjan says:

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

  35. anonymous says:

    so brief but fair enough, thanx

  36. charu says:

    excellent

  37. Joe says:

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

  38. ashok chauhan says:

    very good exellent explenetion

  39. Madhuparna Mukherjee says:

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

  40. ashok chauhan says:

    exellent explenetion

  41. Javahere.com says:

    Excellent post on jsp life cycle ! thanks a lot!

  42. chetnath says:

    very easy and nice example

  43. Anonymous says:

    good example for the life cycle

  44. Anonymous says:

    Good one

  45. radha says:

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

  46. guru says:

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

  47. Nagaraj says:

    excellent.

  48. Anonymous says:

    simple and understandable………! nice work.

  49. Shilpa says:

    Lifecycle explaination is Excellent

  50. Anonymous says:

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

  51. mohan says:

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

  52. Anonymous says:

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

  53. hassan syed says:

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

  54. rohan says:

    very very simple and nice site thanks admin

  55. Anonymous says:

    Good

  56. Jinesh says:

    Great work

    I understood the JSp lifecycle fully

  57. ayush says:

    thanks bro…..it’s really helpful

  58. Ammu says:

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

  59. Ammu says:

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

  60. sonya says:

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

  61. vidhya says:

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

  62. Julfiur Rahman says:

    its really nice ………

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

  64. nirav jain says:

    figure for jsp life cycle is not given here..

Comments are closed.