Is it the jdk compiler? Or the Tomcat(or other web server e.g. WebLogic)? If Tomcat produces the class files,does the class files pass by any compiling-check,like java compling check?
3 Answers
Tomcat is calling internal java compiler,
compiler - Which compiler Ant should use to compile JSP pages. The valid values for this are the same as for the compiler attribute of Ant's javac task. If the value is not set, then the default Eclipse JDT Java compiler will be used instead of using Ant.
compilerSourceVM - What JDK version are the source files compatible with(Default value: 1.6)
compilerTargetVM -> What JDK version are the generated files compatible with? (Default value: 1.6)
see also pre compile JSP using Tomcat
Apache Tomcat 6.0 uses Eclipse JDT Java compiler to perform JSP java source code compilation.
See also using WebLogic compiler in Tomcat
JSP compilers are very much like regular Java compilers, with the main exception being that they take JSP files as "source code" instead of .java files.
-
Add tomact 7 documentation – Ori Marko Aug 16 '17 at 14:16
The subject of JSP compilation is the responsibility of the Application Server (in that sense, you can say that "Tomcat" or "Weblogic" compiles the JSP).
For example, Tomcat does this with the Jasper Engine, JBoss does the same, Weblogic also compile the JSPs automatically
... the JSP Servlet automatically calls the WebLogic JSP compiler to process your JSP pages ...
The basic principle being that
- You can compile JSPs at runtime : (in Tomcat and JBoss, but I guess in many servers) there is an internal, server wide, ServletFilter intercepting *.jsp *.jpsx, that handles the request to the server's internal compilation engine if need be.
- You can compile at packaging time, with various tools (tomcat provides a Ant task, Weblogic has a specific module for that, sometimes even maven plugins are created, ...)
How (by which tool) the actual bytecode generation is done, is unspecified as far as I remember. Tomcat uses Eclipse JDT but allows the use of other compilers with a specific option, weblogic uses javac by default and also allows an override.
See also : How does jsp work?

- 9,088
- 2
- 31
- 38
The servlet container(like tomcat) compile the jsp to java file ,and then compile the java file to class file through JDTCompiler
or AntCompiler
,the following code is implementation of create target compiler in Tomcat:
public Compiler createCompiler() throws JasperException {
if(this.jspCompiler != null) {
return this.jspCompiler;
} else {
this.jspCompiler = null;
if(this.options.getCompiler() == null) {
this.jspCompiler = this.createCompiler("org.apache.jasper.compiler.JDTCompiler");
if(this.jspCompiler == null) {
this.jspCompiler = this.createCompiler("org.apache.jasper.compiler.AntCompiler");
}
} else {
this.jspCompiler = this.createCompiler("org.apache.jasper.compiler.AntCompiler");
if(this.jspCompiler == null) {
this.jspCompiler = this.createCompiler("org.apache.jasper.compiler.JDTCompiler");
}
}
if(this.jspCompiler == null) {
throw new IllegalStateException(Localizer.getMessage("jsp.error.compiler"));
} else {
this.jspCompiler.init(this, this.jsw);
return this.jspCompiler;
}
}
}

- 999
- 8
- 9