This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JSP Life Cycle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP Life Cycle" Watch "JSP Life Cycle" New topic

JSP Life Cycle

Satyajeet Kadam
Ranch Hand

Joined: Oct 19, 2006
Posts: 224

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()?

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

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.

[My Blog]
All roads lead to JavaRanch
Consider Paul's rocket mass heater.
subject: JSP Life Cycle
It's not a secret anymore!