Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 771 | blopes | 1 | <!DOCTYPE html SYSTEM "about:legacy-compat"> |
| 2 | <html lang="en"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="./images/docs-stylesheet.css" rel="stylesheet" type="text/css"><title>Apache Tomcat 9 (9.0.112) - Jasper 2 JSP Engine How To</title></head><body><div id="wrapper"><header><div id="header"><div><div><div class="logo noPrint"><a href="https://tomcat.apache.org/"><img alt="Tomcat Home" src="./images/tomcat.png"></a></div><div style="height: 1px;"></div><div class="asfLogo noPrint"><a href="https://www.apache.org/" target="_blank"><img src="./images/asf-logo.svg" alt="The Apache Software Foundation" style="width: 266px; height: 83px;"></a></div><h1>Apache Tomcat 9</h1><div class="versionInfo"> |
||
| 3 | Version 9.0.112, |
||
| 4 | <time datetime="2025-11-06">Nov 6 2025</time></div><div style="height: 1px;"></div><div style="clear: left;"></div></div></div></div></header><div id="middle"><div><div id="mainLeft" class="noprint"><div><nav><div><h2>Links</h2><ul><li><a href="index.html">Docs Home</a></li><li><a href="https://cwiki.apache.org/confluence/display/TOMCAT/FAQ">FAQ</a></li></ul></div><div><h2>User Guide</h2><ul><li><a href="introduction.html">1) Introduction</a></li><li><a href="setup.html">2) Setup</a></li><li><a href="appdev/index.html">3) First webapp</a></li><li><a href="deployer-howto.html">4) Deployer</a></li><li><a href="manager-howto.html">5) Manager</a></li><li><a href="host-manager-howto.html">6) Host Manager</a></li><li><a href="realm-howto.html">7) Realms and AAA</a></li><li><a href="security-manager-howto.html">8) Security Manager</a></li><li><a href="jndi-resources-howto.html">9) JNDI Resources</a></li><li><a href="jndi-datasource-examples-howto.html">10) JDBC DataSources</a></li><li><a href="class-loader-howto.html">11) Classloading</a></li><li><a href="jasper-howto.html">12) JSPs</a></li><li><a href="ssl-howto.html">13) SSL/TLS</a></li><li><a href="ssi-howto.html">14) SSI</a></li><li><a href="cgi-howto.html">15) CGI</a></li><li><a href="proxy-howto.html">16) Proxy Support</a></li><li><a href="mbeans-descriptors-howto.html">17) MBeans Descriptors</a></li><li><a href="default-servlet.html">18) Default Servlet</a></li><li><a href="cluster-howto.html">19) Clustering</a></li><li><a href="balancer-howto.html">20) Load Balancer</a></li><li><a href="connectors.html">21) Connectors</a></li><li><a href="monitoring.html">22) Monitoring and Management</a></li><li><a href="logging.html">23) Logging</a></li><li><a href="apr.html">24) APR/Native</a></li><li><a href="virtual-hosting-howto.html">25) Virtual Hosting</a></li><li><a href="aio.html">26) Advanced IO</a></li><li><a href="maven-jars.html">27) Mavenized</a></li><li><a href="security-howto.html">28) Security Considerations</a></li><li><a href="windows-service-howto.html">29) Windows Service</a></li><li><a href="windows-auth-howto.html">30) Windows Authentication</a></li><li><a href="jdbc-pool.html">31) Tomcat's JDBC Pool</a></li><li><a href="web-socket-howto.html">32) WebSocket</a></li><li><a href="rewrite.html">33) Rewrite</a></li><li><a href="cdi.html">34) CDI 2 and JAX-RS</a></li><li><a href="graal.html">35) AOT/GraalVM Support</a></li></ul></div><div><h2>Reference</h2><ul><li><a href="RELEASE-NOTES.txt">Release Notes</a></li><li><a href="config/index.html">Configuration</a></li><li><a href="api/index.html">Tomcat Javadocs</a></li><li><a href="servletapi/index.html">Servlet 4.0 Javadocs</a></li><li><a href="jspapi/index.html">JSP 2.3 Javadocs</a></li><li><a href="elapi/index.html">EL 3.0 Javadocs</a></li><li><a href="websocketapi/index.html">WebSocket 1.1 Javadocs</a></li><li><a href="jaspicapi/index.html">JASPIC 1.1 Javadocs</a></li><li><a href="annotationapi/index.html">Common Annotations 1.3 Javadocs</a></li><li><a href="https://tomcat.apache.org/connectors-doc/">JK 1.2 Documentation</a></li></ul></div><div><h2>Apache Tomcat Development</h2><ul><li><a href="building.html">Building</a></li><li><a href="changelog.html">Changelog</a></li><li><a href="https://cwiki.apache.org/confluence/display/TOMCAT/Tomcat+Versions">Status</a></li><li><a href="developers.html">Developers</a></li><li><a href="architecture/index.html">Architecture</a></li><li><a href="tribes/introduction.html">Tribes</a></li></ul></div></nav></div></div><div id="mainRight"><div id="content"><h2>Jasper 2 JSP Engine How To</h2><h3 id="Table_of_Contents">Table of Contents</h3><div class="text"> |
||
| 5 | <ul><li><a href="#Introduction">Introduction</a></li><li><a href="#Configuration">Configuration</a></li><li><a href="#Known_issues">Known issues</a></li><li><a href="#Production_Configuration">Production Configuration</a></li><li><a href="#Web_Application_Compilation">Web Application Compilation</a></li><li><a href="#Optimisation">Optimisation</a></li></ul> |
||
| 6 | </div><h3 id="Introduction">Introduction</h3><div class="text"> |
||
| 7 | |||
| 8 | <p>Tomcat 9.0 uses the Jasper 2 JSP Engine to implement |
||
| 9 | the <a href="https://cwiki.apache.org/confluence/display/TOMCAT/Specifications">JavaServer Pages 2.3</a> |
||
| 10 | specification.</p> |
||
| 11 | |||
| 12 | <p>Jasper 2 has been redesigned to significantly improve performance over |
||
| 13 | the original Jasper. In addition to general code improvements the following |
||
| 14 | changes were made:</p> |
||
| 15 | <ul> |
||
| 16 | <li><strong>JSP Custom Tag Pooling</strong> - The java objects instantiated |
||
| 17 | for JSP Custom Tags can now be pooled and reused. This significantly boosts |
||
| 18 | the performance of JSP pages which use custom tags.</li> |
||
| 19 | <li><strong>Background JSP compilation</strong> - If you make a change to |
||
| 20 | a JSP page which had already been compiled Jasper 2 can recompile that |
||
| 21 | page in the background. The previously compiled JSP page will still be |
||
| 22 | available to serve requests. Once the new page has been compiled |
||
| 23 | successfully it will replace the old page. This helps improve availability |
||
| 24 | of your JSP pages on a production server.</li> |
||
| 25 | <li><strong>Recompile JSP when included page changes</strong> - Jasper 2 |
||
| 26 | can now detect when a page included at compile time from a JSP has changed |
||
| 27 | and then recompile the parent JSP.</li> |
||
| 28 | <li><strong>JDT used to compile JSP pages</strong> - The |
||
| 29 | Eclipse JDT Java compiler is now used to perform JSP java source code |
||
| 30 | compilation. This compiler loads source dependencies from the container |
||
| 31 | classloader. Ant and javac can still be used.</li> |
||
| 32 | </ul> |
||
| 33 | |||
| 34 | |||
| 35 | <p>Jasper is implemented using the servlet class |
||
| 36 | <code>org.apache.jasper.servlet.JspServlet</code>.</p> |
||
| 37 | |||
| 38 | </div><h3 id="Configuration">Configuration</h3><div class="text"> |
||
| 39 | |||
| 40 | <p>By default Jasper is configured for use when doing web application |
||
| 41 | development. See the section <a href="#Production_Configuration"> |
||
| 42 | Production Configuration</a> for information on configuring Jasper |
||
| 43 | for use on a production Tomcat server.</p> |
||
| 44 | |||
| 45 | <p>The servlet which implements Jasper is configured using init parameters |
||
| 46 | in your global <code>$CATALINA_BASE/conf/web.xml</code>. |
||
| 47 | </p> |
||
| 48 | <ul> |
||
| 49 | <li><strong>checkInterval</strong> - If development is false and checkInterval |
||
| 50 | is greater than zero, background compiles are enabled. checkInterval is the time |
||
| 51 | in seconds between checks to see if a JSP page (and its dependent files) needs |
||
| 52 | to be recompiled. Default <code>0</code> seconds.</li> |
||
| 53 | |||
| 54 | <li><strong>classdebuginfo</strong> - Should the class file be compiled with |
||
| 55 | debugging information? <code>true</code> or <code>false</code>, default |
||
| 56 | <code>true</code>. |
||
| 57 | </li> |
||
| 58 | |||
| 59 | <li><strong>classpath</strong> - Defines the class path to be used to compile |
||
| 60 | the generated servlets. This parameter only has an effect if the ServletContext |
||
| 61 | attribute org.apache.jasper.Constants.SERVLET_CLASSPATH is not set. This |
||
| 62 | attribute is always set when Jasper is used within Tomcat. By default the |
||
| 63 | classpath is created dynamically based on the current web application.</li> |
||
| 64 | |||
| 65 | <li><strong>compiler</strong> - Which compiler Ant should use to compile JSP |
||
| 66 | pages. The valid values for this are the same as for the compiler attribute of |
||
| 67 | Ant's |
||
| 68 | <a href="https://ant.apache.org/manual/Tasks/javac.html#compilervalues">javac</a> |
||
| 69 | task. If the value is not set, then the default Eclipse JDT Java compiler will |
||
| 70 | be used instead of using Ant. There is no default value. If this attribute is |
||
| 71 | set then <code>setenv.[sh|bat]</code> should be used to add |
||
| 72 | <code>ant.jar</code>, <code>ant-launcher.jar</code> and <code>tools.jar</code> |
||
| 73 | to the <code>CLASSPATH</code> environment variable.</li> |
||
| 74 | |||
| 75 | <li><strong>compilerSourceVM</strong> - What JDK version are the source files |
||
| 76 | compatible with? (Default value: <code>1.8</code>)</li> |
||
| 77 | |||
| 78 | <li><strong>compilerTargetVM</strong> - What JDK version are the generated files |
||
| 79 | compatible with? (Default value: <code>1.8</code>)</li> |
||
| 80 | |||
| 81 | <li><strong>development</strong> - Is Jasper used in development mode? If true, |
||
| 82 | the frequency at which JSPs are checked for modification may be specified via |
||
| 83 | the modificationTestInterval parameter.<code>true</code> or <code>false</code>, |
||
| 84 | default <code>true</code>.</li> |
||
| 85 | |||
| 86 | <li><strong>displaySourceFragment</strong> - Should a source fragment be |
||
| 87 | included in exception messages? <code>true</code> or <code>false</code>, |
||
| 88 | default <code>true</code>.</li> |
||
| 89 | |||
| 90 | <li><strong>dumpSmap</strong> - Should the SMAP info for JSR45 debugging be |
||
| 91 | dumped to a file? <code>true</code> or <code>false</code>, default |
||
| 92 | <code>false</code>. <code>false</code> if suppressSmap is true.</li> |
||
| 93 | |||
| 94 | <li><strong>enablePooling</strong> - Determines whether tag handler pooling is |
||
| 95 | enabled. This is a compilation option. It will not alter the behaviour of JSPs |
||
| 96 | that have already been compiled. <code>true</code> or <code>false</code>, |
||
| 97 | default <code>true</code>. |
||
| 98 | </li> |
||
| 99 | |||
| 100 | <li><strong>engineOptionsClass</strong> - Allows specifying the Options class |
||
| 101 | used to configure Jasper. If not present, the default EmbeddedServletOptions |
||
| 102 | will be used. This option is ignored if running under a SecurityManager. |
||
| 103 | </li> |
||
| 104 | |||
| 105 | <li><strong>errorOnUseBeanInvalidClassAttribute</strong> - Should Jasper issue |
||
| 106 | an error when the value of the class attribute in an useBean action is not a |
||
| 107 | valid bean class? <code>true</code> or <code>false</code>, default |
||
| 108 | <code>true</code>.</li> |
||
| 109 | |||
| 110 | <li><strong>fork</strong> - Have Ant fork JSP page compiles so they are |
||
| 111 | performed in a separate JVM from Tomcat? <code>true</code> or |
||
| 112 | <code>false</code>, default <code>true</code>.</li> |
||
| 113 | |||
| 114 | <li><strong>genStringAsCharArray</strong> - Should text strings be generated as char |
||
| 115 | arrays, to improve performance in some cases? Default <code>false</code>.</li> |
||
| 116 | |||
| 117 | <li><strong>ieClassId</strong> - Deprecated. Will be removed in Tomact 10.1. |
||
| 118 | The class-id value to be sent to Internet |
||
| 119 | Explorer when using <jsp:plugin> tags. Default |
||
| 120 | <code>clsid:8AD9C840-044E-11D1-B3E9-00805F499D93</code>.</li> |
||
| 121 | |||
| 122 | <li><strong>javaEncoding</strong> - Java file encoding to use for generating |
||
| 123 | java source files. Default <code>UTF8</code>.</li> |
||
| 124 | |||
| 125 | <li><strong>keepgenerated</strong> - Should we keep the generated Java source |
||
| 126 | code for each page instead of deleting it? <code>true</code> or |
||
| 127 | <code>false</code>, default <code>true</code>.</li> |
||
| 128 | |||
| 129 | <li><strong>mappedfile</strong> - Should we generate static content with one |
||
| 130 | print statement per input line, to ease debugging? |
||
| 131 | <code>true</code> or <code>false</code>, default <code>true</code>.</li> |
||
| 132 | |||
| 133 | <li><strong>maxLoadedJsps</strong> - The maximum number of JSPs that will be |
||
| 134 | loaded for a web application. If more than this number of JSPs are loaded, the |
||
| 135 | least recently used JSPs will be unloaded so that the number of JSPs loaded at |
||
| 136 | any one time does not exceed this limit. A value of zero or less indicates no |
||
| 137 | limit. Default <code>-1</code></li> |
||
| 138 | |||
| 139 | <li><strong>jspIdleTimeout</strong> - The amount of time in seconds a JSP can be |
||
| 140 | idle before it is unloaded. A value of zero or less indicates never unload. |
||
| 141 | Default <code>-1</code></li> |
||
| 142 | |||
| 143 | <li><strong>modificationTestInterval</strong> - Causes a JSP (and its dependent |
||
| 144 | files) to not be checked for modification during the specified time interval |
||
| 145 | (in seconds) from the last time the JSP was checked for modification. A value of |
||
| 146 | |||
| 147 | only. Default is <code>4</code> seconds.</li> |
||
| 148 | |||
| 149 | <li><strong>recompileOnFail</strong> - If a JSP compilation fails should the |
||
| 150 | modificationTestInterval be ignored and the next access trigger a re-compilation |
||
| 151 | attempt? Used in development mode only and is disabled by default as compilation |
||
| 152 | may be expensive and could lead to excessive resource usage.</li> |
||
| 153 | |||
| 154 | <li><strong>scratchdir</strong> - What scratch directory should we use when |
||
| 155 | compiling JSP pages? Default is the work directory for the current web |
||
| 156 | application. This option is ignored if running under a SecurityManager.</li> |
||
| 157 | |||
| 158 | <li><strong>suppressSmap</strong> - Should the generation of SMAP info for JSR45 |
||
| 159 | debugging be suppressed? <code>true</code> or <code>false</code>, default |
||
| 160 | <code>false</code>.</li> |
||
| 161 | |||
| 162 | <li><strong>trimSpaces</strong> - Should template text that consists entirely of |
||
| 163 | whitespace be removed from the output (<code>true</code>), replaced with a |
||
| 164 | single space (<code>single</code>) or left unchanged (<code>false</code>)? |
||
| 165 | Alternatively, the <code>extended</code> option will remove leading and trailing |
||
| 166 | whitespace from template text and collapse sequences of whitespace and newlines |
||
| 167 | within the template text to a single new line. Note that if a JSP page or tag |
||
| 168 | file specifies a <code>trimDirectiveWhitespaces</code> value of |
||
| 169 | <code>true</code>, that will take precedence over this configuration setting for |
||
| 170 | that page/tag. Default <code>false</code>.</li> |
||
| 171 | |||
| 172 | <li><strong>xpoweredBy</strong> - Determines whether X-Powered-By response |
||
| 173 | header is added by generated servlet. <code>true</code> or <code>false</code>, |
||
| 174 | default <code>false</code>.</li> |
||
| 175 | |||
| 176 | <li><strong>strictQuoteEscaping</strong> - When scriptlet expressions are used |
||
| 177 | for attribute values, should the rules in JSP.1.6 for the escaping of quote |
||
| 178 | characters be strictly applied? <code>true</code> or <code>false</code>, default |
||
| 179 | <code>true</code>.</li> |
||
| 180 | |||
| 181 | <li><strong>quoteAttributeEL</strong> - When EL is used in an attribute value |
||
| 182 | on a JSP page, should the rules for quoting of attributes described in JSP.1.6 |
||
| 183 | be applied to the expression? <code>true</code> or <code>false</code>, default |
||
| 184 | <code>true</code>.</li> |
||
| 185 | </ul> |
||
| 186 | |||
| 187 | <p>The Java compiler from Eclipse JDT in included as the default compiler. It is |
||
| 188 | an advanced Java compiler which will load all dependencies from the Tomcat class |
||
| 189 | loader, which will help tremendously when compiling on large installations with |
||
| 190 | tens of JARs. On fast servers, this will allow sub-second recompilation cycles |
||
| 191 | for even large JSP pages.</p> |
||
| 192 | |||
| 193 | <p>Apache Ant, which was used in previous Tomcat releases, can be used instead |
||
| 194 | of the new compiler by configuring the compiler attribute as explained above. |
||
| 195 | </p> |
||
| 196 | |||
| 197 | <p>If you need to change the JSP Servlet settings for an application you can |
||
| 198 | override the default configuration by re-defining the JSP Servlet in |
||
| 199 | <code>/WEB-INF/web.xml</code>. However, this may cause problems if you attempt |
||
| 200 | to deploy the application on another container as the JSP Servlet class may |
||
| 201 | not be recognised. You can work-around this problem by using the Tomcat specific |
||
| 202 | <code>/WEB-INF/tomcat-web.xml</code> deployment descriptor. The format is |
||
| 203 | identical to <code>/WEB-INF/web.xml</code>. It will override any default |
||
| 204 | settings but not those in <code>/WEB-INF/web.xml</code>. Since it is Tomcat |
||
| 205 | specific, it will only be processed when the application is deployed on |
||
| 206 | Tomcat.</p> |
||
| 207 | |||
| 208 | </div><h3 id="Known_issues">Known issues</h3><div class="text"> |
||
| 209 | |||
| 210 | <p>As described in |
||
| 211 | <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=39089"> |
||
| 212 | bug 39089</a>, a known JVM issue, |
||
| 213 | <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6294277"> |
||
| 214 | bug 6294277</a>, may cause a |
||
| 215 | <code>java.lang.InternalError: name is too long to represent</code> exception |
||
| 216 | when compiling very large JSPs. If this is observed then it may be worked around |
||
| 217 | by using one of the following: |
||
| 218 | </p> |
||
| 219 | <ul> |
||
| 220 | <li>reduce the size of the JSP</li> |
||
| 221 | <li>disable SMAP generation and JSR-045 support by setting |
||
| 222 | <code>suppressSmap</code> to <code>true</code>.</li> |
||
| 223 | </ul> |
||
| 224 | |||
| 225 | </div><h3 id="Production_Configuration">Production Configuration</h3><div class="text"> |
||
| 226 | |||
| 227 | <p>The main JSP optimization which can be done is precompilation of JSPs. |
||
| 228 | However, this might not be possible (for example, when using the |
||
| 229 | jsp-property-group feature) or practical, in which case the configuration of the |
||
| 230 | Jasper servlet becomes critical.</p> |
||
| 231 | |||
| 232 | <p>When using Jasper 2 in a production Tomcat server you should consider making |
||
| 233 | the following changes from the default configuration.</p> |
||
| 234 | <ul> |
||
| 235 | <li><strong>development</strong> - To disable on access checks for JSP |
||
| 236 | pages compilation set this to <code>false</code>.</li> |
||
| 237 | <li><strong>genStringAsCharArray</strong> - To generate slightly more efficient |
||
| 238 | char arrays, set this to <code>true</code>.</li> |
||
| 239 | <li><strong>modificationTestInterval</strong> - If development has to be set to |
||
| 240 | <code>true</code> for any reason (such as dynamic generation of JSPs), setting |
||
| 241 | this to a high value will improve performance a lot.</li> |
||
| 242 | <li><strong>trimSpaces</strong> - To remove unnecessary bytes from the response, |
||
| 243 | consider setting this to <code>single</code> or <code>extended</code>.</li> |
||
| 244 | </ul> |
||
| 245 | |||
| 246 | </div><h3 id="Web_Application_Compilation">Web Application Compilation</h3><div class="text"> |
||
| 247 | |||
| 248 | <p>Using Ant is the preferred way to compile web applications using JSPC. Note |
||
| 249 | that when pre-compiling JSPs, SMAP information will only be included in the |
||
| 250 | final classes if suppressSmap is false and compile is true. |
||
| 251 | Use the script given below (a similar script is included in the "deployer" |
||
| 252 | download) to precompile a webapp: |
||
| 253 | </p> |
||
| 254 | |||
| 255 | <div class="codeBox"><pre><code><project name="Webapp Precompilation" default="all" basedir="."> |
||
| 256 | |||
| 257 | <import file="${tomcat.home}/bin/catalina-tasks.xml"/> |
||
| 258 | |||
| 259 | <target name="jspc"> |
||
| 260 | |||
| 261 | <jasper |
||
| 262 | validateXml="false" |
||
| 263 | uriroot="${webapp.path}" |
||
| 264 | webXmlInclude="${webapp.path}/WEB-INF/generated_web.xml" |
||
| 265 | outputDir="${webapp.path}/WEB-INF/src" /> |
||
| 266 | |||
| 267 | </target> |
||
| 268 | |||
| 269 | <target name="compile"> |
||
| 270 | |||
| 271 | <mkdir dir="${webapp.path}/WEB-INF/classes"/> |
||
| 272 | <mkdir dir="${webapp.path}/WEB-INF/lib"/> |
||
| 273 | |||
| 274 | <javac destdir="${webapp.path}/WEB-INF/classes" |
||
| 275 | debug="on" failonerror="false" |
||
| 276 | srcdir="${webapp.path}/WEB-INF/src" |
||
| 277 | excludes="**/*.smap"> |
||
| 278 | <classpath> |
||
| 279 | <pathelement location="${webapp.path}/WEB-INF/classes"/> |
||
| 280 | <fileset dir="${webapp.path}/WEB-INF/lib"> |
||
| 281 | <include name="*.jar"/> |
||
| 282 | </fileset> |
||
| 283 | <pathelement location="${tomcat.home}/lib"/> |
||
| 284 | <fileset dir="${tomcat.home}/lib"> |
||
| 285 | <include name="*.jar"/> |
||
| 286 | </fileset> |
||
| 287 | <fileset dir="${tomcat.home}/bin"> |
||
| 288 | <include name="*.jar"/> |
||
| 289 | </fileset> |
||
| 290 | </classpath> |
||
| 291 | <include name="**" /> |
||
| 292 | <exclude name="tags/**" /> |
||
| 293 | </javac> |
||
| 294 | |||
| 295 | </target> |
||
| 296 | |||
| 297 | <target name="all" depends="jspc,compile"> |
||
| 298 | </target> |
||
| 299 | |||
| 300 | <target name="cleanup"> |
||
| 301 | <delete> |
||
| 302 | <fileset dir="${webapp.path}/WEB-INF/src"/> |
||
| 303 | <fileset dir="${webapp.path}/WEB-INF/classes/org/apache/jsp"/> |
||
| 304 | </delete> |
||
| 305 | </target> |
||
| 306 | |||
| 307 | </project></code></pre></div> |
||
| 308 | |||
| 309 | <p> |
||
| 310 | The following command line can be used to run the script |
||
| 311 | (replacing the tokens with the Tomcat base path and the path to the webapp |
||
| 312 | which should be precompiled): |
||
| 313 | </p> |
||
| 314 | <div class="codeBox"><pre><code>$ANT_HOME/bin/ant -Dtomcat.home=<$TOMCAT_HOME> -Dwebapp.path=<$WEBAPP_PATH></code></pre></div> |
||
| 315 | |||
| 316 | |||
| 317 | <p> |
||
| 318 | Then, the declarations and mappings for the servlets which were generated |
||
| 319 | during the precompilation must be added to the web application deployment |
||
| 320 | descriptor. Insert the <code>${webapp.path}/WEB-INF/generated_web.xml</code> |
||
| 321 | at the right place inside the <code>${webapp.path}/WEB-INF/web.xml</code> file. |
||
| 322 | Restart the web application (using the manager) and test it to verify it is |
||
| 323 | running fine with precompiled servlets. An appropriate token placed in the |
||
| 324 | web application deployment descriptor may also be used to automatically |
||
| 325 | insert the generated servlet declarations and mappings using Ant filtering |
||
| 326 | capabilities. This is actually how all the webapps distributed with Tomcat |
||
| 327 | are automatically compiled as part of the build process. |
||
| 328 | </p> |
||
| 329 | |||
| 330 | <p> |
||
| 331 | At the jasper task you can use the option <code>addWebXmlMappings</code> for |
||
| 332 | automatic merge the <code>${webapp.path}/WEB-INF/generated_web.xml</code> |
||
| 333 | with the current web application deployment descriptor at |
||
| 334 | <code>${webapp.path}/WEB-INF/web.xml</code>. |
||
| 335 | </p> |
||
| 336 | |||
| 337 | <p> |
||
| 338 | When you want to use a specific version of Java for your JSP's, add the |
||
| 339 | javac compiler task attributes <code>source</code> and <code>target</code> with |
||
| 340 | appropriate values. For example, <code>16</code> to compile JSPs for Java 16. |
||
| 341 | </p> |
||
| 342 | |||
| 343 | <p> |
||
| 344 | For production you may wish to disable debug info with |
||
| 345 | <code>debug="off"</code>. |
||
| 346 | </p> |
||
| 347 | |||
| 348 | <p> |
||
| 349 | When you don't want to stop the JSP generation at first JSP syntax error, use |
||
| 350 | <code>failOnError="false"</code> and with |
||
| 351 | <code>showSuccess="true"</code> all successful <i>JSP to Java</i> |
||
| 352 | generation are printed out. Sometimes it is very helpful, when you cleanup the |
||
| 353 | generate java source files at <code>${webapp.path}/WEB-INF/src</code> |
||
| 354 | and the compile JSP servlet classes at |
||
| 355 | <code>${webapp.path}/WEB-INF/classes/org/apache/jsp</code>. |
||
| 356 | </p> |
||
| 357 | |||
| 358 | <p><strong>Hints:</strong></p> |
||
| 359 | <ul> |
||
| 360 | <li> When you switch to another Tomcat release, then regenerate and recompile |
||
| 361 | your JSP's with the new Tomcat version.</li> |
||
| 362 | <li>Use java system property at server runtime to disable PageContext pooling |
||
| 363 | <code>org.apache.jasper.runtime.JspFactoryImpl.USE_POOL=false</code>. |
||
| 364 | and limit the buffering with |
||
| 365 | <code>org.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true</code>. Note |
||
| 366 | that changing from the defaults may affect performance, but it will vary |
||
| 367 | depending on the application.</li> |
||
| 368 | </ul> |
||
| 369 | </div><h3 id="Optimisation">Optimisation</h3><div class="text"> |
||
| 370 | <p> |
||
| 371 | There are a number of extension points provided within Jasper that enable the |
||
| 372 | user to optimise the behaviour for their environment. |
||
| 373 | </p> |
||
| 374 | |||
| 375 | <p> |
||
| 376 | The first of these extension points is the tag plug-in mechanism. This allows |
||
| 377 | alternative implementations of tag handlers to be provided for a web application |
||
| 378 | to use. Tag plug-ins are registered via a <code>tagPlugins.xml</code> file |
||
| 379 | located under <code>WEB-INF</code>. A sample plug-in for the JSTL is included |
||
| 380 | with Jasper. |
||
| 381 | </p> |
||
| 382 | |||
| 383 | <p> |
||
| 384 | The second extension point is the Expression Language interpreter. Alternative |
||
| 385 | interpreters may be configured through the <code>ServletContext</code>. See the |
||
| 386 | <code>ELInterpreterFactory</code> javadoc for details of how to configure an |
||
| 387 | alternative EL interpreter. A alternative interpreter primarily targeting tag |
||
| 388 | settings is provided at |
||
| 389 | <code>org.apache.jasper.optimizations.ELInterpreterTagSetters</code>. See the |
||
| 390 | javadoc for details of the optimisations and the impact they have on |
||
| 391 | specification compliance. |
||
| 392 | </p> |
||
| 393 | |||
| 394 | <p> |
||
| 395 | An extension point is also provided for coercion of String values to Enums. It |
||
| 396 | is provided at |
||
| 397 | <code>org.apache.jasper.optimizations.StringInterpreterEnum</code>. See the |
||
| 398 | javadoc for details of the optimisations and the impact they have on |
||
| 399 | specification compliance. |
||
| 400 | </p> |
||
| 401 | </div></div></div></div></div><footer><div id="footer"> |
||
| 402 | Copyright © 1999-2025, The Apache Software Foundation |
||
| 403 | <br> |
||
| 404 | Apache Tomcat, Tomcat, Apache, the Apache Tomcat logo and the Apache logo |
||
| 405 | are either registered trademarks or trademarks of the Apache Software |
||
| 406 | Foundation. |
||
| 407 | </div></footer></div></body></html> |