刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 1 | <html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Apache Tomcat 7 (7.0.77) - Jasper 2 JSP Engine How To</title><meta name="author" content="Glenn L. Nielsen"><meta name="author" content="Peter Rossbach"><style type="text/css" media="print">
|
| 2 | .noPrint {display: none;}
|
| 3 | td#mainBody {width: 100%;}
|
| 4 | </style><style type="text/css">
|
| 5 | code {background-color:rgb(224,255,255);padding:0 0.1em;}
|
| 6 | code.attributeName, code.propertyName {background-color:transparent;}
|
| 7 |
|
| 8 |
|
| 9 | table {
|
| 10 | border-collapse: collapse;
|
| 11 | text-align: left;
|
| 12 | }
|
| 13 | table *:not(table) {
|
| 14 | /* Prevent border-collapsing for table child elements like <div> */
|
| 15 | border-collapse: separate;
|
| 16 | }
|
| 17 |
|
| 18 | th {
|
| 19 | text-align: left;
|
| 20 | }
|
| 21 |
|
| 22 |
|
| 23 | div.codeBox pre code, code.attributeName, code.propertyName, code.noHighlight, .noHighlight code {
|
| 24 | background-color: transparent;
|
| 25 | }
|
| 26 | div.codeBox {
|
| 27 | overflow: auto;
|
| 28 | margin: 1em 0;
|
| 29 | }
|
| 30 | div.codeBox pre {
|
| 31 | margin: 0;
|
| 32 | padding: 4px;
|
| 33 | border: 1px solid #999;
|
| 34 | border-radius: 5px;
|
| 35 | background-color: #eff8ff;
|
| 36 | display: table; /* To prevent <pre>s from taking the complete available width. */
|
| 37 | /*
|
| 38 | When it is officially supported, use the following CSS instead of display: table
|
| 39 | to prevent big <pre>s from exceeding the browser window:
|
| 40 | max-width: available;
|
| 41 | width: min-content;
|
| 42 | */
|
| 43 | }
|
| 44 |
|
| 45 | div.codeBox pre.wrap {
|
| 46 | white-space: pre-wrap;
|
| 47 | }
|
| 48 |
|
| 49 |
|
| 50 | table.defaultTable tr, table.detail-table tr {
|
| 51 | border: 1px solid #CCC;
|
| 52 | }
|
| 53 |
|
| 54 | table.defaultTable tr:nth-child(even), table.detail-table tr:nth-child(even) {
|
| 55 | background-color: #FAFBFF;
|
| 56 | }
|
| 57 |
|
| 58 | table.defaultTable tr:nth-child(odd), table.detail-table tr:nth-child(odd) {
|
| 59 | background-color: #EEEFFF;
|
| 60 | }
|
| 61 |
|
| 62 | table.defaultTable th, table.detail-table th {
|
| 63 | background-color: #88b;
|
| 64 | color: #fff;
|
| 65 | }
|
| 66 |
|
| 67 | table.defaultTable th, table.defaultTable td, table.detail-table th, table.detail-table td {
|
| 68 | padding: 5px 8px;
|
| 69 | }
|
| 70 |
|
| 71 |
|
| 72 | p.notice {
|
| 73 | border: 1px solid rgb(255, 0, 0);
|
| 74 | background-color: rgb(238, 238, 238);
|
| 75 | color: rgb(0, 51, 102);
|
| 76 | padding: 0.5em;
|
| 77 | margin: 1em 2em 1em 1em;
|
| 78 | }
|
| 79 | </style></head><body bgcolor="#ffffff" text="#000000" link="#525D76" alink="#525D76" vlink="#525D76"><table border="0" width="100%" cellspacing="0"><!--PAGE HEADER--><tr><td><!--PROJECT LOGO--><a href="http://tomcat.apache.org/"><img src="./images/tomcat.gif" align="right" alt="
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 80 | The Apache Tomcat Servlet/JSP Container
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 81 | " border="0"></a></td><td><h1><font face="arial,helvetica,sanserif">Apache Tomcat 7</font></h1><font face="arial,helvetica,sanserif">Version 7.0.77, Mar 28 2017</font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img src="./images/asf-logo.svg" align="right" alt="Apache Logo" border="0" style="width: 266px;height: 83px;"></a></td></tr></table><table border="0" width="100%" cellspacing="4"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><tr><!--LEFT SIDE NAVIGATION--><td width="20%" valign="top" nowrap class="noPrint"><p><strong>Links</strong></p><ul><li><a href="index.html">Docs Home</a></li><li><a href="http://wiki.apache.org/tomcat/FAQ">FAQ</a></li><li><a href="#comments_section">User Comments</a></li></ul><p><strong>User Guide</strong></p><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="realm-howto.html">6) Realms and AAA</a></li><li><a href="security-manager-howto.html">7) Security Manager</a></li><li><a href="jndi-resources-howto.html">8) JNDI Resources</a></li><li><a href="jndi-datasource-examples-howto.html">9) JDBC DataSources</a></li><li><a href="class-loader-howto.html">10) Classloading</a></li><li><a href="jasper-howto.html">11) JSPs</a></li><li><a href="ssl-howto.html">12) SSL/TLS</a></li><li><a href="ssi-howto.html">13) SSI</a></li><li><a href="cgi-howto.html">14) CGI</a></li><li><a href="proxy-howto.html">15) Proxy Support</a></li><li><a href="mbeans-descriptors-howto.html">16) MBeans Descriptors</a></li><li><a href="default-servlet.html">17) Default Servlet</a></li><li><a href="cluster-howto.html">18) Clustering</a></li><li><a href="balancer-howto.html">19) Load Balancer</a></li><li><a href="connectors.html">20) Connectors</a></li><li><a href="monitoring.html">21) Monitoring and Management</a></li><li><a href="logging.html">22) Logging</a></li><li><a href="apr.html">23) APR/Native</a></li><li><a href="virtual-hosting-howto.html">24) Virtual Hosting</a></li><li><a href="aio.html">25) Advanced IO</a></li><li><a href="extras.html">26) Additional Components</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></ul><p><strong>Reference</strong></p><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 Javadocs</a></li><li><a href="jspapi/index.html">JSP 2.2 Javadocs</a></li><li><a href="elapi/index.html">EL 2.2 Javadocs</a></li><li><a href="websocketapi/index.html">WebSocket 1.1 Javadocs</a></li><li><a href="http://tomcat.apache.org/connectors-doc/">JK 1.2 Documentation</a></li></ul><p><strong>Apache Tomcat Development</strong></p><ul><li><a href="building.html">Building</a></li><li><a href="changelog.html">Changelog</a></li><li><a href="http://wiki.apache.org/tomcat/TomcatVersions">Status</a></li><li><a href="developers.html">Developers</a></li><li><a href="architecture/index.html">Architecture</a></li><li><a href="funcspecs/index.html">Functional Specs.</a></li><li><a href="tribes/introduction.html">Tribes</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td width="80%" valign="top" align="left" id="mainBody"><h1>Jasper 2 JSP Engine How To</h1><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Table of Contents"><!--()--></a><a name="Table_of_Contents"><strong>Table of Contents</strong></a></font></td></tr><tr><td><blockquote>
|
| 82 | <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>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 83 | </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Introduction"><strong>Introduction</strong></a></font></td></tr><tr><td><blockquote>
|
| 84 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 85 | <p>Tomcat 7.0 uses the Jasper 2 JSP Engine to implement
|
| 86 | the <a href="http://wiki.apache.org/tomcat/Specifications">JavaServer Pages 2.2</a>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 87 | specification.</p>
|
| 88 |
|
| 89 | <p>Jasper 2 has been redesigned to significantly improve performance over
|
| 90 | the original Jasper. In addition to general code improvements the following
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 91 | changes were made:</p>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 92 | <ul>
|
| 93 | <li><strong>JSP Custom Tag Pooling</strong> - The java objects instantiated
|
| 94 | for JSP Custom Tags can now be pooled and reused. This significantly boosts
|
| 95 | the performance of JSP pages which use custom tags.</li>
|
| 96 | <li><strong>Background JSP compilation</strong> - If you make a change to
|
| 97 | a JSP page which had already been compiled Jasper 2 can recompile that
|
| 98 | page in the background. The previously compiled JSP page will still be
|
| 99 | available to serve requests. Once the new page has been compiled
|
| 100 | successfully it will replace the old page. This helps improve availability
|
| 101 | of your JSP pages on a production server.</li>
|
| 102 | <li><strong>Recompile JSP when included page changes</strong> - Jasper 2
|
| 103 | can now detect when a page included at compile time from a JSP has changed
|
| 104 | and then recompile the parent JSP.</li>
|
| 105 | <li><strong>JDT used to compile JSP pages</strong> - The
|
| 106 | Eclipse JDT Java compiler is now used to perform JSP java source code
|
| 107 | compilation. This compiler loads source dependencies from the container
|
| 108 | classloader. Ant and javac can still be used.</li>
|
| 109 | </ul>
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 110 |
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 111 |
|
| 112 | <p>Jasper is implemented using the servlet class
|
| 113 | <code>org.apache.jasper.servlet.JspServlet</code>.</p>
|
| 114 |
|
| 115 | </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Configuration"><strong>Configuration</strong></a></font></td></tr><tr><td><blockquote>
|
| 116 |
|
| 117 | <p>By default Jasper is configured for use when doing web application
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 118 | development. See the section <a href="#Production_Configuration">
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 119 | Production Configuration</a> for information on configuring Jasper
|
| 120 | for use on a production Tomcat server.</p>
|
| 121 |
|
| 122 | <p>The servlet which implements Jasper is configured using init parameters
|
| 123 | in your global <code>$CATALINA_BASE/conf/web.xml</code>.
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 124 | </p>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 125 | <ul>
|
| 126 | <li><strong>checkInterval</strong> - If development is false and checkInterval
|
| 127 | is greater than zero, background compiles are enabled. checkInterval is the time
|
| 128 | in seconds between checks to see if a JSP page (and its dependent files) needs
|
| 129 | to be recompiled. Default <code>0</code> seconds.</li>
|
| 130 |
|
| 131 | <li><strong>classdebuginfo</strong> - Should the class file be compiled with
|
| 132 | debugging information? <code>true</code> or <code>false</code>, default
|
| 133 | <code>true</code>.
|
| 134 | </li>
|
| 135 |
|
| 136 | <li><strong>classpath</strong> - Defines the class path to be used to compile
|
| 137 | the generated servlets. This parameter only has an effect if the ServletContext
|
| 138 | attribute org.apache.jasper.Constants.SERVLET_CLASSPATH is not set. This
|
| 139 | attribute is always set when Jasper is used within Tomcat. By default the
|
| 140 | classpath is created dynamically based on the current web application.</li>
|
| 141 |
|
| 142 | <li><strong>compiler</strong> - Which compiler Ant should use to compile JSP
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 143 | pages. The valid values for this are the same as for the compiler attribute of
|
| 144 | Ant's
|
| 145 | <a href="http://ant.apache.org/manual/Tasks/javac.html#compilervalues">javac</a>
|
| 146 | task. If the value is not set, then the default Eclipse JDT Java compiler will
|
| 147 | be used instead of using Ant. There is no default value. If this attribute is
|
| 148 | set then <code>setenv.[sh|bat]</code> should be used to add
|
| 149 | <code>ant.jar</code>, <code>ant-launcher.jar</code> and <code>tools.jar</code>
|
| 150 | to the <code>CLASSPATH</code> environment variable.</li>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 151 |
|
| 152 | <li><strong>compilerSourceVM</strong> - What JDK version are the source files
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 153 | compatible with? (Default value: <code>1.6</code>)</li>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 154 |
|
| 155 | <li><strong>compilerTargetVM</strong> - What JDK version are the generated files
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 156 | compatible with? (Default value: <code>1.6</code>)</li>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 157 |
|
| 158 | <li><strong>development</strong> - Is Jasper used in development mode? If true,
|
| 159 | the frequency at which JSPs are checked for modification may be specified via
|
| 160 | the modificationTestInterval parameter.<code>true</code> or <code>false</code>,
|
| 161 | default <code>true</code>.</li>
|
| 162 |
|
| 163 | <li><strong>displaySourceFragment</strong> - Should a source fragment be
|
| 164 | included in exception messages? <code>true</code> or <code>false</code>,
|
| 165 | default <code>true</code>.</li>
|
| 166 |
|
| 167 | <li><strong>dumpSmap</strong> - Should the SMAP info for JSR45 debugging be
|
| 168 | dumped to a file? <code>true</code> or <code>false</code>, default
|
| 169 | <code>false</code>. <code>false</code> if suppressSmap is true.</li>
|
| 170 |
|
| 171 | <li><strong>enablePooling</strong> - Determines whether tag handler pooling is
|
| 172 | enabled. This is a compilation option. It will not alter the behaviour of JSPs
|
| 173 | that have already been compiled. <code>true</code> or <code>false</code>,
|
| 174 | default <code>true</code>.
|
| 175 | </li>
|
| 176 |
|
| 177 | <li><strong>engineOptionsClass</strong> - Allows specifying the Options class
|
| 178 | used to configure Jasper. If not present, the default EmbeddedServletOptions
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 179 | will be used. This option is ignored if running under a SecurityManager.
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 180 | </li>
|
| 181 |
|
| 182 | <li><strong>errorOnUseBeanInvalidClassAttribute</strong> - Should Jasper issue
|
| 183 | an error when the value of the class attribute in an useBean action is not a
|
| 184 | valid bean class? <code>true</code> or <code>false</code>, default
|
| 185 | <code>true</code>.</li>
|
| 186 |
|
| 187 | <li><strong>fork</strong> - Have Ant fork JSP page compiles so they are
|
| 188 | performed in a separate JVM from Tomcat? <code>true</code> or
|
| 189 | <code>false</code>, default <code>true</code>.</li>
|
| 190 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 191 | <li><strong>genStringAsCharArray</strong> - Should text strings be generated as char
|
| 192 | arrays, to improve performance in some cases? Default <code>false</code>.</li>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 193 |
|
| 194 | <li><strong>ieClassId</strong> - The class-id value to be sent to Internet
|
| 195 | Explorer when using <jsp:plugin> tags. Default
|
| 196 | <code>clsid:8AD9C840-044E-11D1-B3E9-00805F499D93</code>.</li>
|
| 197 |
|
| 198 | <li><strong>javaEncoding</strong> - Java file encoding to use for generating
|
| 199 | java source files. Default <code>UTF8</code>.</li>
|
| 200 |
|
| 201 | <li><strong>keepgenerated</strong> - Should we keep the generated Java source
|
| 202 | code for each page instead of deleting it? <code>true</code> or
|
| 203 | <code>false</code>, default <code>true</code>.</li>
|
| 204 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 205 | <li><strong>mappedfile</strong> - Should we generate static content with one
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 206 | print statement per input line, to ease debugging?
|
| 207 | <code>true</code> or <code>false</code>, default <code>true</code>.</li>
|
| 208 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 209 | <li><strong>maxLoadedJsps</strong> - The maximum number of JSPs that will be
|
| 210 | loaded for a web application. If more than this number of JSPs are loaded, the
|
| 211 | least recently used JSPs will be unloaded so that the number of JSPs loaded at
|
| 212 | any one time does not exceed this limit. A value of zero or less indicates no
|
| 213 | limit. Default <code>-1</code></li>
|
| 214 |
|
| 215 | <li><strong>jspIdleTimeout</strong> - The amount of time in seconds a JSP can be
|
| 216 | idle before it is unloaded. A value of zero or less indicates never unload.
|
| 217 | Default <code>-1</code></li>
|
| 218 |
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 219 | <li><strong>modificationTestInterval</strong> - Causes a JSP (and its dependent
|
| 220 | files) to not be checked for modification during the specified time interval
|
| 221 | (in seconds) from the last time the JSP was checked for modification. A value of
|
| 222 | 0 will cause the JSP to be checked on every access. Used in development mode
|
| 223 | only. Default is <code>4</code> seconds.</li>
|
| 224 |
|
| 225 | <li><strong>recompileOnFail</strong> - If a JSP compilation fails should the
|
| 226 | modificationTestInterval be ignored and the next access trigger a re-compilation
|
| 227 | attempt? Used in development mode only and is disabled by default as compilation
|
| 228 | may be expensive and could lead to excessive resource usage.</li>
|
| 229 |
|
| 230 | <li><strong>scratchdir</strong> - What scratch directory should we use when
|
| 231 | compiling JSP pages? Default is the work directory for the current web
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 232 | application. This option is ignored if running under a SecurityManager.</li>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 233 |
|
| 234 | <li><strong>suppressSmap</strong> - Should the generation of SMAP info for JSR45
|
| 235 | debugging be suppressed? <code>true</code> or <code>false</code>, default
|
| 236 | <code>false</code>.</li>
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 237 |
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 238 | <li><strong>trimSpaces</strong> - Should white spaces in template text between
|
| 239 | actions or directives be trimmed ?, default <code>false</code>.</li>
|
| 240 |
|
| 241 | <li><strong>xpoweredBy</strong> - Determines whether X-Powered-By response
|
| 242 | header is added by generated servlet. <code>true</code> or <code>false</code>,
|
| 243 | default <code>false</code>.</li>
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 244 |
|
| 245 | <li><strong>quoteAttributeEL</strong> - When EL is used in an attribute value
|
| 246 | on a JSP page, should the rules for quoting of attributes described in JSP.1.6
|
| 247 | be applied to the expression? <code>true</code> or <code>false</code>, default
|
| 248 | <code>true</code>.</li>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 249 | </ul>
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 250 |
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 251 |
|
| 252 | <p>The Java compiler from Eclipse JDT in included as the default compiler. It is
|
| 253 | an advanced Java compiler which will load all dependencies from the Tomcat class
|
| 254 | loader, which will help tremendously when compiling on large installations with
|
| 255 | tens of JARs. On fast servers, this will allow sub-second recompilation cycles
|
| 256 | for even large JSP pages.</p>
|
| 257 |
|
| 258 | <p>Apache Ant, which was used in previous Tomcat releases, can be used instead
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 259 | of the new compiler by configuring the compiler attribute as explained above.
|
| 260 | </p>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 261 |
|
| 262 | </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Known issues"><!--()--></a><a name="Known_issues"><strong>Known issues</strong></a></font></td></tr><tr><td><blockquote>
|
| 263 |
|
| 264 | <p>As described in
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 265 | <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=39089">
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 266 | bug 39089</a>, a known JVM issue,
|
| 267 | <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6294277">
|
| 268 | bug 6294277</a>, may cause a
|
| 269 | <code>java.lang.InternalError: name is too long to represent</code> exception
|
| 270 | when compiling very large JSPs. If this is observed then it may be worked around
|
| 271 | by using one of the following:
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 272 | </p>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 273 | <ul>
|
| 274 | <li>reduce the size of the JSP</li>
|
| 275 | <li>disable SMAP generation and JSR-045 support by setting
|
| 276 | <code>suppressSmap</code> to <code>true</code>.</li>
|
| 277 | </ul>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 278 |
|
| 279 | </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Production Configuration"><!--()--></a><a name="Production_Configuration"><strong>Production Configuration</strong></a></font></td></tr><tr><td><blockquote>
|
| 280 |
|
| 281 | <p>The main JSP optimization which can be done is precompilation of JSPs.
|
| 282 | However, this might not be possible (for example, when using the
|
| 283 | jsp-property-group feature) or practical, in which case the configuration of the
|
| 284 | Jasper servlet becomes critical.</p>
|
| 285 |
|
| 286 | <p>When using Jasper 2 in a production Tomcat server you should consider making
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 287 | the following changes from the default configuration.</p>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 288 | <ul>
|
| 289 | <li><strong>development</strong> - To disable on access checks for JSP
|
| 290 | pages compilation set this to <code>false</code>.</li>
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 291 | <li><strong>genStringAsCharArray</strong> - To generate slightly more efficient
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 292 | char arrays, set this to <code>true</code>.</li>
|
| 293 | <li><strong>modificationTestInterval</strong> - If development has to be set to
|
| 294 | <code>true</code> for any reason (such as dynamic generation of JSPs), setting
|
| 295 | this to a high value will improve performance a lot.</li>
|
| 296 | <li><strong>trimSpaces</strong> - To remove useless bytes from the response,
|
| 297 | set this to <code>true</code>.</li>
|
| 298 | </ul>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 299 |
|
| 300 | </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Web Application Compilation"><!--()--></a><a name="Web_Application_Compilation"><strong>Web Application Compilation</strong></a></font></td></tr><tr><td><blockquote>
|
| 301 |
|
| 302 | <p>Using Ant is the preferred way to compile web applications using JSPC. Note
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 303 | that when pre-compiling JSPs, SMAP information will only be included in the
|
| 304 | final classes if suppressSmap is false and compile is true.
|
| 305 | Use the script given below (a similar script is included in the "deployer"
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 306 | download) to precompile a webapp:
|
| 307 | </p>
|
| 308 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 309 | <div class="codeBox"><pre><code><project name="Webapp Precompilation" default="all" basedir=".">
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 310 |
|
| 311 | <import file="${tomcat.home}/bin/catalina-tasks.xml"/>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 312 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 313 | <target name="jspc">
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 314 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 315 | <jasper
|
| 316 | validateXml="false"
|
| 317 | uriroot="${webapp.path}"
|
| 318 | webXmlFragment="${webapp.path}/WEB-INF/generated_web.xml"
|
| 319 | outputDir="${webapp.path}/WEB-INF/src" />
|
| 320 |
|
| 321 | </target>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 322 |
|
| 323 | <target name="compile">
|
| 324 |
|
| 325 | <mkdir dir="${webapp.path}/WEB-INF/classes"/>
|
| 326 | <mkdir dir="${webapp.path}/WEB-INF/lib"/>
|
| 327 |
|
| 328 | <javac destdir="${webapp.path}/WEB-INF/classes"
|
| 329 | optimize="off"
|
| 330 | debug="on" failonerror="false"
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 331 | srcdir="${webapp.path}/WEB-INF/src"
|
| 332 | excludes="**/*.smap">
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 333 | <classpath>
|
| 334 | <pathelement location="${webapp.path}/WEB-INF/classes"/>
|
| 335 | <fileset dir="${webapp.path}/WEB-INF/lib">
|
| 336 | <include name="*.jar"/>
|
| 337 | </fileset>
|
| 338 | <pathelement location="${tomcat.home}/lib"/>
|
| 339 | <fileset dir="${tomcat.home}/lib">
|
| 340 | <include name="*.jar"/>
|
| 341 | </fileset>
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 342 | <fileset dir="${tomcat.home}/bin">
|
| 343 | <include name="*.jar"/>
|
| 344 | </fileset>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 345 | </classpath>
|
| 346 | <include name="**" />
|
| 347 | <exclude name="tags/**" />
|
| 348 | </javac>
|
| 349 |
|
| 350 | </target>
|
| 351 |
|
| 352 | <target name="all" depends="jspc,compile">
|
| 353 | </target>
|
| 354 |
|
| 355 | <target name="cleanup">
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 356 | <delete>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 357 | <fileset dir="${webapp.path}/WEB-INF/src"/>
|
| 358 | <fileset dir="${webapp.path}/WEB-INF/classes/org/apache/jsp"/>
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 359 | </delete>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 360 | </target>
|
| 361 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 362 | </project></code></pre></div>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 363 |
|
| 364 | <p>
|
| 365 | The following command line can be used to run the script
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 366 | (replacing the tokens with the Tomcat base path and the path to the webapp
|
| 367 | which should be precompiled):
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 368 | </p>
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 369 | <div class="codeBox"><pre><code>$ANT_HOME/bin/ant -Dtomcat.home=<$TOMCAT_HOME> -Dwebapp.path=<$WEBAPP_PATH></code></pre></div>
|
| 370 |
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 371 |
|
| 372 | <p>
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 373 | Then, the declarations and mappings for the servlets which were generated
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 374 | during the precompilation must be added to the web application deployment
|
| 375 | descriptor. Insert the <code>${webapp.path}/WEB-INF/generated_web.xml</code>
|
| 376 | at the right place inside the <code>${webapp.path}/WEB-INF/web.xml</code> file.
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 377 | Restart the web application (using the manager) and test it to verify it is
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 378 | running fine with precompiled servlets. An appropriate token placed in the
|
| 379 | web application deployment descriptor may also be used to automatically
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 380 | insert the generated servlet declarations and mappings using Ant filtering
|
| 381 | capabilities. This is actually how all the webapps distributed with Tomcat
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 382 | are automatically compiled as part of the build process.
|
| 383 | </p>
|
| 384 |
|
| 385 | <p>
|
| 386 | At the jasper task you can use the option <code>addWebXmlMappings</code> for
|
| 387 | automatic merge the <code>${webapp.path}/WEB-INF/generated_web.xml</code>
|
| 388 | with the current web application deployment descriptor at
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 389 | <code>${webapp.path}/WEB-INF/web.xml</code>. When you want to use Java 6
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 390 | features inside your jsp's, add the following javac compiler task attributes:
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 391 | <code>source="1.6" target="1.6"</code>. For live
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 392 | applications you can also compile with <code>optimize="on"</code> and
|
| 393 | without debug info <code>debug="off"</code>.
|
| 394 | </p>
|
| 395 |
|
| 396 | <p>
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 397 | When you don't want to stop the jsp generation at first jsp syntax error, use
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 398 | <code>failOnError="false"</code>and with
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 399 | <code>showSuccess="true"</code> all successful <i>jsp to java</i>
|
| 400 | generation are printed out. Sometimes it is very helpful, when you cleanup the
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 401 | generate java source files at <code>${webapp.path}/WEB-INF/src</code>
|
| 402 | and the compile jsp servlet classes at
|
| 403 | <code>${webapp.path}/WEB-INF/classes/org/apache/jsp</code>.
|
| 404 | </p>
|
| 405 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 406 | <p><strong>Hints:</strong></p>
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 407 | <ul>
|
| 408 | <li> When you switch to another Tomcat release, then regenerate and recompile
|
| 409 | your jsp's with the new Tomcat version.</li>
|
| 410 | <li>Use java system property at server runtime to disable PageContext pooling
|
| 411 | <code>org.apache.jasper.runtime.JspFactoryImpl.USE_POOL=false</code>.
|
| 412 | and limit the buffering with
|
| 413 | <code>org.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true</code>. Note
|
| 414 | that changing from the defaults may affect performance, but it will vary
|
| 415 | depending on the application.</li>
|
| 416 | </ul>
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 417 | </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Optimisation"><strong>Optimisation</strong></a></font></td></tr><tr><td><blockquote>
|
| 418 | <p>
|
| 419 | There are a number of extension points provided within Jasper that enable the
|
| 420 | user to optimise the behaviour for their environment.
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 421 | </p>
|
| 422 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 423 | <p>
|
| 424 | The first of these extension points is the tag plug-in mechanism. This allows
|
| 425 | alternative implementations of tag handlers to be provided for a web application
|
| 426 | to use. Tag plug-ins are registered via a <code>tagPlugins.xml</code> file
|
| 427 | located under <code>WEB-INF</code>. A sample plug-in for the JSTL is included
|
| 428 | with Jasper.
|
| 429 | </p>
|
| 430 |
|
| 431 | <p>
|
| 432 | The second extension point is the Expression Language interpreter. Alternative
|
| 433 | interpreters may be configured through the <code>ServletContext</code>. See the
|
| 434 | <code>ELInterpreterFactory</code> javadoc for details of how to configure an
|
| 435 | alternative EL interpreter.
|
| 436 | </p>
|
| 437 | </blockquote></td></tr></table></td></tr><tr class="noPrint"><td width="20%" valign="top" nowrap class="noPrint"></td><td width="80%" valign="top" align="left"><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="comments_section" id="comments_section"><strong>Comments</strong></a></font></td></tr><tr><td><blockquote><p class="notice"><strong>Notice: </strong>This comments section collects your suggestions
|
| 438 | on improving documentation for Apache Tomcat.<br><br>
|
| 439 | If you have trouble and need help, read
|
| 440 | <a href="http://tomcat.apache.org/findhelp.html">Find Help</a> page
|
| 441 | and ask your question on the tomcat-users
|
| 442 | <a href="http://tomcat.apache.org/lists.html">mailing list</a>.
|
| 443 | Do not ask such questions here. This is not a Q&A section.<br><br>
|
| 444 | The Apache Comments System is explained <a href="./comments.html">here</a>.
|
| 445 | Comments may be removed by our moderators if they are either
|
| 446 | implemented or considered invalid/off-topic.</p><script type="text/javascript"><!--//--><![CDATA[//><!--
|
| 447 | var comments_shortname = 'tomcat';
|
| 448 | var comments_identifier = 'http://tomcat.apache.org/tomcat-7.0-doc/jasper-howto.html';
|
| 449 | (function(w, d) {
|
| 450 | if (w.location.hostname.toLowerCase() == "tomcat.apache.org") {
|
| 451 | d.write('<div id="comments_thread"><\/div>');
|
| 452 | var s = d.createElement('script');
|
| 453 | s.type = 'text/javascript';
|
| 454 | s.async = true;
|
| 455 | s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
|
| 456 | (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
|
| 457 | }
|
| 458 | else {
|
| 459 | d.write('<div id="comments_thread"><strong>Comments are disabled for this page at the moment.<\/strong><\/div>');
|
| 460 | }
|
| 461 | })(window, document);
|
| 462 | //--><!]]></script></blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font color="#525D76" size="-1"><em>
|
| 463 | Copyright © 1999-2017, Apache Software Foundation
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 464 | </em></font></div></td></tr></table></body></html> |