I am wondering does JSP ever get compiled ? The reasons why that I am asking is because whenever I deploy my Java EE application on the web server I only see those servlet and beans class file in the WEB-INF folder as they are compiled, but not that JSP, so how does it work, and what’s the logical flow and the big picture of the normal request/response cycle.
Share
Basically:
In your servlet container, the JSP servlet is mapped to any URL that ends in
.jsp(usually)When one of those
.jspURLs is requested, the request goes to the JSP servlet. Then, this servlet checks if the JSP is already compiled.If the JSP is not compiled yet, the JSP servlet translates the JSP to some Java source code implementing the
Servletinterface. Then it compiles this Java source code to a.classfile. This.classfile usually is located somewhere in the servlet container’s work directory for the application.Once the JSP servlet has compiled the servlet class from the JSP source code, it just forwards the request to this servlet class.
The thing is, unless you specifically precompile your JSP, all this happens at runtime, and hidden in the servlet container’s work directory, so it is “invisible”. Also have in mind that this is what happens “conceptually”, several optimizations are possible in this workflow.