Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JSP Life Cycle

Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Head First Book:Please refer diagram on page no 307 .

Step 5: The continer inistantiates the servlet and causes the servlet's jspInit() method to run.

In diagram the container is calling jspInit() on myJSP_jsp and then this object becomes servet ie(myJSP_jsp) which then ready to handle the client request.

Q1)I am confused,I think the container must call _jspInit().Because if we see the generated source code there is no jspInit().

Q2)On page no:305 it is written that jspInit():This method is called from init().If we compared this statement with diagram in step no5
servlet is getting generated after calling jspInit().So how can init() can call jspInit()?

Posts: 14691
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1) JSPs must implement the HttpJspPage interface, which extends the JspPage interface, which defines jspInit and jspDestroy methods. The container must call jspInit(). What you are looking at is a container generated class implementing HttpJspPage. If you are using Tomcat, the class is org.apache.jasper.runtime.HttpJspBase, which implements HttpJspPage.

Q2) The servlet is not generated after calling jspInit. It is generated during the translation phase. There, your JSP becomes a servlet. The first time it is instanciated, its init() method will be called, which in turn will call the jspInit() method.
Not so fast naughty spawn! I want you to know about
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic