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