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.
JSP Compilation --> page translation
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.
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
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.
The objective 8.5 however States:
Identify and put in sequence the following elements of the JSP page lifecycle:
JSP page compilation
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.
I Hope This Helps
Carl Trusiak, SCJP2
"...translation is normally done the first time the page is requested.
...the JSP is translated into a servlet and compiled..."
Therefore, translation then compilation..
SCJP SCJD SCWCD
[This message has been edited by Ken Zrobok (edited September 18, 2001).]
"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"