Apache Tomcat Development
The Apache Tomcat 5.5 Servlet/JSP Container
Jasper 2 JSP Engine How To
Tomcat 5.5 uses the Jasper 2 JSP Engine to implement
the JavaServer Pages 2.0
Jasper 2 has been redesigned to significantly improve performance over
the original Jasper. In addition to general code improvements the following
changes were made:
- JSP Custom Tag Pooling - The java objects instantiated
for JSP Custom Tags can now be pooled and reused. This significantly boosts
the performance of JSP pages which use custom tags.
- Background JSP compilation - If you make a change to
a JSP page which had already been compiled Jasper 2 can recompile that
page in the background. The previously compiled JSP page will still be
available to serve requests. Once the new page has been compiled
successfully it will replace the old page. This helps improve availability
of your JSP pages on a production server.
- Recompile JSP when included page changes - Jasper 2
can now detect when a page included at compile time from a JSP has changed
and then recompile the parent JSP.
- JDT used to compile JSP pages - The
Eclipse JDT Java compiler is now used to perform JSP java source code
compilation. This compiler loads source dependencies from the container
classloader. Ant and javac can still be used.
Jasper is implemented using the servlet class
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
- checkInterval - If development is false and reloading is
true, background compiles are enabled. checkInterval is the time in seconds
between checks to see if a JSP page needs to be recompiled. Default
- compiler - Which compiler Ant should use to compile JSP
pages. See the Ant documentation for more information. If the value is not set,
then the default Eclipse JDT Java compiler will be used instead of using Ant.
No default value.
- classdebuginfo - Should the class file be compiled with
- classpath - Defines the class path to be used to compile
the generated servlets. This parameter only has an effect if the ServletContext
attribute org.apache.jasper.Constants.SERVLET_CLASSPATH is not set. This
attribute is always set when Jasper is used within Tomcat. By default the
classpath is created dynamically based on the current web application.
- compilerSourceVM - What JDK version are the source files compatible with?
The default value depends on the version of Java that runs your Tomcat.
If it is Java 5.0 or later, the value will be
- compilerTargetVM - What JDK version are the generated files compatible with?
The default value is the same as for compilerSourceVM.
- development - Is Jasper used in development mode (will
check for JSP modification on every access)?
- enablePooling - Determines whether tag handler pooling is
- engineOptionsClass - Allows specifying the Options class
used to configure Jasper. If not present, the default EmbeddedServletOptions
will be used.
- ieClassId - The class-id value to be sent to Internet
Explorer when using <jsp:plugin> tags. Default
- fork - Have Ant fork JSP page compiles so they are
performed in a separate JVM from Tomcat?
- javaEncoding - Java file encoding to use for generating
java source files. Default
- genStrAsCharArray - Should text strings be generated as char
arrays, to improve performance in some cases? Default
- keepgenerated - Should we keep the generated Java source
code for each page instead of deleting it?
- mappedfile - Should we generate static content with one
print statement per input line, to ease debugging?
- modificationTestInterval - Checks for modification for a given
JSP file (and all its dependent files) will be performed only once every specified amount
of seconds. Setting this to 0 will cause the JSP to be checked on every access.
- reloading - Should Jasper check for modified JSPs?
- scratchdir - What scratch directory should we use when
compiling JSP pages? Default is the work directory for the current web
- trimSpaces - Should white spaces in template text between
actions or directives be trimmed ?, default
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. This new compiler will be updated to support the Java 5 syntax as soon as
Apache Ant, which was used in previous Tomcat releases, can be used instead instead of
the new compiler by simply removing the
and placing the
ant.jar file from the latest Ant distribution in the
common/lib folder. If you do this, you also need to use the "javac"
argument to catalina.sh.
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:
- reduce the size of the JSP
- disable SMAP generation and JSR-045 support by setting
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.
- development - To disable on access checks for JSP
pages compilation set this to
- genStringAsCharArray - To generate slightly more efficient
char arrays, set this to
- modificationTestInterval - If development has to be set to
true for any reason (such as dynamic generation of JSPs), setting
this to a high value will improve performance a lot.
- trimSpaces - To remove useless bytes from the response,
set this to
If you wish to use
Jikes to compile JSP pages:
- From your Ant installation, copy ant.jar
and (if it's available: Ant 1.5 and later) ant-launcher.jar to
- Download and install jikes. jikes must support the -encoding option.
jikes -help to verify that it was built with support
- Set the init parameter
- Define the property
-Dbuild.compiler.emacs=true when starting
Tomcat by adding it to your
CATALINA_OPTS environment variable.
This changes how jikes outputs error messages so that it is compatible with
- If you get an error reporting that jikes can't use UTF8 encoding, try
setting the init parameter