Jasper 2 has been redesigned to significantly improve performance over
the orignal 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 availablity
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
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.

checkInterval - If development is false and checkInterval
is greater than zero, background compiles are enabled. checkInterval is the time
in seconds between checks to see if a JSP page (and its dependent files) needs
to be recompiled. Default 0 seconds.

classdebuginfo - Should the class file be compiled with
debugging information? true or false, default
true.

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.

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.

development - Is Jasper used in development mode? If true,
the frequency at which JSPs are checked for modification may be specified via
the modificationTestInterval parameter.true or false,
default true.

displaySourceFragment - Should a source fragment be
included in exception messages? true or false,
default true.

dumpSmap - Should the SMAP info for JSR45 debugging be
dumped to a file? true or false, default
false. false if suppressSmap is true.

keepgenerated - Should we keep the generated Java source
code for each page instead of deleting it? true or
false, default true.

mappedfile - Should we generate static content with one
print statement per input line, to ease debugging?
true or false, default true.

modificationTestInterval - Causes a JSP (and its dependent
files) to not be checked for modification during the specified time interval
(in seconds) from the last time the JSP was checked for modification. A value of
0 will cause the JSP to be checked on every access. Used in development mode
only. Default is 4 seconds.

scratchdir - What scratch directory should we use when
compiling JSP pages? Default is the work directory for the current web
application.

suppressSmap - Should the generation of SMAP info for JSR45
debugging be suppressed? true or false, default
false.

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 simply removing the lib/jasper-jdt.jar file,
and placing the ant.jar file from the latest Ant distribution in
the lib folder. If you do this, you also need to use the "javac"
argument to catalina.sh.

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 false.

genStringAsCharArray - To generate slightly more efficient
char arrays, set this to true.

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 true.

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 jasper2 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 Java 5
features inside your jsp's, add the following javac compiler task attributes:
source="1.5" target="1.5". For live
applications you can also compile with optimize="on" and
without debug info 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 successfull jsp to java
generation are printed out. Sometimes it is very helpfull, 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:

When you switch to another Tomcat release, then regenerate and recompile
your jsp's with the new Tomcat version.

Use java system property at server runtime to disable tag pooling
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.

Download and install jikes. jikes must support the -encoding option.
Execute jikes -help to verify that it was built with support
for -encoding.

Set the init parameter compiler to jikes.

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
Jasper.

If you get an error reporting that jikes can't use UTF8 encoding, try
setting the init parameter javaEncoding to
ISO-8859-1.