
Tomcat 9.0 uses the Jasper 2 JSP Engine to implement the JavaServer Pages 2.3 specification.
Jasper 2 has been redesigned to significantly improve performance over the original Jasper. In addition to general code improvements the following changes were made:
Jasper is implemented using the servlet class
org.apache.jasper.servlet.JspServlet.
By default Jasper is configured for use when doing web application development. See the section Production Configuration for information on configuring Jasper for use on a production Tomcat server.
The servlet which implements Jasper is configured using init parameters
in your global $CATALINA_BASE/conf/web.xml.
0 seconds.true or false, default
true.
setenv.[sh|bat] should be used to add
ant.jar, ant-launcher.jar and tools.jar
to the CLASSPATH environment variable.1.8)1.8)true or false,
default true.true or false,
default true.true or false, default
false. false if suppressSmap is true.true or false,
default true.
true or false, default
true.true or
false, default true.false.clsid:8AD9C840-044E-11D1-B3E9-00805F499D93.UTF8.true or
false, default true.true or false, default true.-1-14 seconds.true or false, default
false.true), replaced with a
single space (single) or left unchanged (false)?
Alternatively, the extended option will remove leading and trailing
whitespace from template text and collapse sequences of whitespace and newlines
within the template text to a single new line. Note that if a JSP page or tag
file specifies a trimDirectiveWhitespaces value of
true, that will take precedence over this configuration setting for
that page/tag. Default false.true or false,
default false.true or false, default
true.true or false, default
true.The Java compiler from Eclipse JDT in included as the default compiler. It is an advanced Java compiler which will load all dependencies from the Tomcat class loader, which will help tremendously when compiling on large installations with tens of JARs. On fast servers, this will allow sub-second recompilation cycles for even large JSP pages.
Apache Ant, which was used in previous Tomcat releases, can be used instead of the new compiler by configuring the compiler attribute as explained above.
If you need to change the JSP Servlet settings for an application you can
override the default configuration by re-defining the JSP Servlet in
/WEB-INF/web.xml. However, this may cause problems if you attempt
to deploy the application on another container as the JSP Servlet class may
not be recognised. You can work-around this problem by using the Tomcat specific
/WEB-INF/tomcat-web.xml deployment descriptor. The format is
identical to /WEB-INF/web.xml. It will override any default
settings but not those in /WEB-INF/web.xml. Since it is Tomcat
specific, it will only be processed when the application is deployed on
Tomcat.
As described in
bug 39089, a known JVM issue,
bug 6294277, may cause a
java.lang.InternalError: name is too long to represent exception
when compiling very large JSPs. If this is observed then it may be worked around
by using one of the following:
suppressSmap to true.The main JSP optimization which can be done is precompilation of JSPs. However, this might not be possible (for example, when using the jsp-property-group feature) or practical, in which case the configuration of the Jasper servlet becomes critical.
When using Jasper 2 in a production Tomcat server you should consider making the following changes from the default configuration.
false.true.true for any reason (such as dynamic generation of JSPs), setting
this to a high value will improve performance a lot.single or extended.Using Ant is the preferred way to compile web applications using JSPC. Note that when pre-compiling JSPs, SMAP information will only be included in the final classes if suppressSmap is false and compile is true. Use the script given below (a similar script is included in the "deployer" download) to precompile a webapp:
<project name="Webapp Precompilation" default="all" basedir=".">
<import file="${tomcat.home}/bin/catalina-tasks.xml"/>
<target name="jspc">
<jasper
validateXml="false"
uriroot="${webapp.path}"
webXmlInclude="${webapp.path}/WEB-INF/generated_web.xml"
outputDir="${webapp.path}/WEB-INF/src" />
</target>
<target name="compile">
<mkdir dir="${webapp.path}/WEB-INF/classes"/>
<mkdir dir="${webapp.path}/WEB-INF/lib"/>
<javac destdir="${webapp.path}/WEB-INF/classes"
debug="on" failonerror="false"
srcdir="${webapp.path}/WEB-INF/src"
excludes="**/*.smap">
<classpath>
<pathelement location="${webapp.path}/WEB-INF/classes"/>
<fileset dir="${webapp.path}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<pathelement location="${tomcat.home}/lib"/>
<fileset dir="${tomcat.home}/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${tomcat.home}/bin">
<include name="*.jar"/>
</fileset>
</classpath>
<include name="**" />
<exclude name="tags/**" />
</javac>
</target>
<target name="all" depends="jspc,compile">
</target>
<target name="cleanup">
<delete>
<fileset dir="${webapp.path}/WEB-INF/src"/>
<fileset dir="${webapp.path}/WEB-INF/classes/org/apache/jsp"/>
</delete>
</target>
</project>The following command line can be used to run the script (replacing the tokens with the Tomcat base path and the path to the webapp which should be precompiled):
$ANT_HOME/bin/ant -Dtomcat.home=<$TOMCAT_HOME> -Dwebapp.path=<$WEBAPP_PATH>
Then, the declarations and mappings for the servlets which were generated
during the precompilation must be added to the web application deployment
descriptor. Insert the ${webapp.path}/WEB-INF/generated_web.xml
at the right place inside the ${webapp.path}/WEB-INF/web.xml file.
Restart the web application (using the manager) and test it to verify it is
running fine with precompiled servlets. An appropriate token placed in the
web application deployment descriptor may also be used to automatically
insert the generated servlet declarations and mappings using Ant filtering
capabilities. This is actually how all the webapps distributed with Tomcat
are automatically compiled as part of the build process.
At the jasper task you can use the option addWebXmlMappings for
automatic merge the ${webapp.path}/WEB-INF/generated_web.xml
with the current web application deployment descriptor at
${webapp.path}/WEB-INF/web.xml.
When you want to use a specific version of Java for your JSP's, add the
javac compiler task attributes source and target with
appropriate values. For example, 16 to compile JSPs for Java 16.
For production you may wish to disable debug info with
debug="off".
When you don't want to stop the JSP generation at first JSP syntax error, use
failOnError="false" and with
showSuccess="true" all successful JSP to Java
generation are printed out. Sometimes it is very helpful, when you cleanup the
generate java source files at ${webapp.path}/WEB-INF/src
and the compile JSP servlet classes at
${webapp.path}/WEB-INF/classes/org/apache/jsp.
Hints:
org.apache.jasper.runtime.JspFactoryImpl.USE_POOL=false.
and limit the buffering with
org.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true. Note
that changing from the defaults may affect performance, but it will vary
depending on the application.There are a number of extension points provided within Jasper that enable the user to optimise the behaviour for their environment.
The first of these extension points is the tag plug-in mechanism. This allows
alternative implementations of tag handlers to be provided for a web application
to use. Tag plug-ins are registered via a tagPlugins.xml file
located under WEB-INF. A sample plug-in for the JSTL is included
with Jasper.
The second extension point is the Expression Language interpreter. Alternative
interpreters may be configured through the ServletContext. See the
ELInterpreterFactory javadoc for details of how to configure an
alternative EL interpreter. A alternative interpreter primarily targeting tag
settings is provided at
org.apache.jasper.optimizations.ELInterpreterTagSetters. See the
javadoc for details of the optimisations and the impact they have on
specification compliance.
An extension point is also provided for coercion of String values to Enums. It
is provided at
org.apache.jasper.optimizations.StringInterpreterEnum. See the
javadoc for details of the optimisations and the impact they have on
specification compliance.