This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Looking over objective 8.5 (JSP lifecycle sequence) I have a question concerning the now famous Ken Zrobok's study guide. In his Order of Events of the lifecycle, he indicates the order as:
JSP Compilation --> page translation
The specification (as far as I can find) makes no real distinction in the translation and compilaiton phases. If it does, it is evidently not in terms elementary enough for me. I consulted the JSp Tutorial on Sun's site http://java.sun.com/j2ee/tutorial/doc/JSPIntro4.html and it is a little more explicit. What I think I understand from reading the tutorial is that (1)The .jsp file is "translated" into a .java file by the container in the translation phase. (2)The .java file is compiled into a .class file in the page compilation phase. Is this correct? If it is, is the above line from Ken's notes incorrect (or badly interpreted by me)? Just wanted to be sure I undestand this point clearly enough. Thanks, Bill
I think you are right. Sun already list those elements in the right order. Translating means translate a JSP to servlet source code. Somebody call this process parsing. Jun HOng
Jun Hong<br />SCJP, SCJD, SCWCD, SCEA<br />IBM Certified Systems Expert(V4.0)
Joined: Sep 05, 2001
Sorry so many mistakes. I think you are right. Sun already listed those elements in the right order. Translating means converting a JSP to servlet source code. People also call this process parsing. Jun Hong
means that first jsp engine compiles the jsp page and finds any error in the page that's why we get compile time errors on jsp page this step invloves two stages
Jsp page compilation (JSP Compilation )
translation into servlet and compilation of servlet (page translation )
second compilation that takes place when the servlet is compiled into class. I think we can not call this step as Page compilation rather it should be called servlet compilation step(I think so). I want to know the exact meaning of these steps. I also mailed my problem to Ken but not got satisfactory answer, anyways thanks Ken for such a quick reply.
I think there is a misconception/misintrepation of the line JSP Compilation --> page translation.In true sense , in a Jsp lifecycle the Compilation phase happens more than once ie once at the time of loading the jsp page in the webserver/jsp container and second at the request processing time. To elaborate Loading phase: when a jsp application is loaded into the container all the static data in form of jsp,html,graphics file is converted/parsed into a .java file(which we term as the background servlet),this .java file is then compiled to the .class file.This whole phase is also reffered to as translation time. Request Processing Phase: when the user makes a request by submitting a form data, the component which the .jsp file refers(either a JavaBean, EJB, or a Servlet)to takes the request parameters and passes it on to the .java file which is compiled again with the new inputs from the components, the compilation of .java file happens each time the request parameters differs.
[This message has been edited by Rishi Singh (edited November 19, 2001).]
Originally posted by Rishi Singh: I think there is a misconception/misintrepation of the line JSP Compilation --> page translation.In true sense , in a Jsp lifecycle the Compilation phase happens more than once ie once at the time of loading the jsp page in the webserver/jsp container and second at the request processing time.
Off the mark by a considerable margin, I'm afraid. What does not happen: translation of html and graphics resources, per-request compilation of a jsp page. What does happen: the jsp page is translated to a Java source file for a servlet. This servlet is subsequently compiled; from that moment on, it's handling HTTP requests like any other servlet. Depending on your application server, the translation + compilation step may either happen during deployment or when the first request for a new or updated jsp comes in. Let's examine a typical implementation in a bit more detail. Not all implementations work in this way! 1. The .jsp extension is mapped to the jsp engine servlet as per the normal servlet mapping rules. When a request for a .jsp file comes in, this servlet gets to handle the request. 2. The jsp engine servlet uses request.getPathInfo() to determine which jsp was invoked, and finds the associated servlet. If the .jsp has not been compiled yet, go to step 4. 3. At regular intervals, it compares the timestamp of the .jsp source file to the compilation time of the associated servlet. If the .jsp is older, or if no check is performed, go to step 6. 4. The servlet is nonexistent or obsolete, so the .jsp file is translated to a servlet .java file. All HTML code is translated to out.println() statements or the like. Custom tags are converted to tag class instantiations and method calls. Any translation-time errors are reported back to the user. 5. If translation was successful, the resultant .java file is compiled into a servlet .class file using either the JDK compiler or a fast alternative such as jikes. Any compile-time errors are processed to convert the .java line number references into .jsp line numbers. 6. The request is forwarded to the servlet implementing the .jsp file, which then handles the request like any other servlet. In a deployed jsp, the usual sequence of events is 1->2->6. Note that none of these steps contains particularly time-consuming operations. This is why jsps are almost as fast and efficient as servlets. - Peter
I think what is confusing everyone is the fact that Sun defines the Translation Phase as "In the translation phase the container locates or creates the JSP page implementation class that corresponds to a given JSP page." in the JSP Specification. I think this means that Compilation is part of the Translation Phase as used there. The objective 8.5 however States: Identify and put in sequence the following elements of the JSP page lifecycle: Page translation JSP page compilation Load class Create instance Call jspInit Call _jspService Call jspDestroy Translation Phase corresponds to Page Translation then Compilation. The translation of a JSP source page into its implementation class can occur 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. Execution Phase corresponds to (in Order) Load class, Create instance, Call jspInit, Call _jspService, Call jspDestroy When the first request is delivered to a JSP page, a jspInit() method, if present, will be called to prepare the page. Similarly, a JSP container may invoke a JSP�s jspDestroy() method to reclaim the resources used by the JSP page at any time when a request is not being serviced. This is the same life-cycle as for servlets.
To agree with Carl and against the section of my notes, here is a snippet from Core Servlets (Marty Hall). "...translation is normally done the first time the page is requested. ...the JSP is translated into a servlet and compiled..." Therefore, translation then compilation.. My apologies... Ken ------------------ Ken Zrobok Java Developer/Trainer SCJPSCJD SCWCD
[This message has been edited by Ken Zrobok (edited September 18, 2001).]
Ken Zrobok<BR>Java Developer/Trainer<BR>SCJP SCJD SCWCD
Joined: Dec 09, 2000
Peter, how do u explain this from the Sun Tutorials.... "when the user loads the page for the first time, the files that make up the application(a jsp, a html, graphics files) are all translated together, without any dynamic data, into one java source file(a.java file)with a name that your jsp implementation defines.Then the .java file is compiled into a .classfile.This entire stage is known as translation time. when the user makes a request of the jsp application , one or more of the application components handles data the user submits or retrieves dynamically from a data store and returns the data to the .java file where it is 'recompiled in the .class file'.The .class file being a Java Servlet returns the data to the client web browser by its service method.when the user makes a web request the component obtains or handles the data again and returns it to the .java file which is compiled again into the .class file.This stage is known as a request time"
Peter den Haan
Joined: Apr 20, 2000
Can you give a URL for that? Without context, at least, it reads like confused nonsense. - Peter