Jetty Logo
Version: 9.4.24-SNAPSHOT
Contact the core Jetty developers at

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development

Chapter 8. Configuring JSP Support

Table of Contents

Configuring JSP

Configuring JSP

This document provides information about configuring Java Server Pages (JSP) for Jetty.

Which JSP Implementation

Jetty uses Jasper from Apache as the default JSP container implementation.

By default the Jetty distribution enables the JSP module, and by default, this module is set to Apache Jasper.


Enables JSP for all webapplications deployed on the server.


Note that the availability of some JSP features may depend on which JSP container implementation you are using. Note also that it may not be possible to precompile your JSPs with one container and deploy to the other.

JSPs and Embedding

If you have an embedded setup for your webapp and wish to use JSPs, you will need to ensure that a JSP engine is correctly initialized.

For Apache, a Servlet Specification 3.1 style ServletContainerInitializer is used to accomplish this. You will need to ensure that this ServletContainerInitializer is run by jetty. Perhaps the easiest way to do this is to enable annotations processing so that Jetty automatically discovers and runs it. The Embedded Examples section includes a worked code example of how to do this.

Alternatively, you can manually wire in the appropriate ServletContainerInitializer as shown in the embedded-jetty-jsp example on GitHub, in which case you will not need the jetty-annotations jar on your classpath, nor include the AnnotationConfiguration in the list of configuration classes.

Precompiling JSPs

You can either follow the instructions on precompilation provided by Apache, or if you are using Maven for your builds, you can use the jetty-jspc-maven plugin to do it for you.

If you have precompiled your JSPs, and have customized the output package prefix (which is org.apache.jsp by default), you should configure your webapp context to tell Jetty about this custom package name. You can do this using a servlet context init-param called org.eclipse.jetty.servlet.jspPackagePrefix.

For example, suppose you have precompiled your JSPs with the custom package prefix of com.acme, then you would add the following lines to your web.xml file:



Both Jetty Maven plugins - jetty-jspc-maven-plugin and the jetty-maven-plugin - will only use Apache Jasper.

Apache JSP Container

By default, the Apache JSP container will look for the Eclipse Java Compiler (jdt). The Jetty distribution ships a copy of this in {$jetty.home}/lib/apache-jsp. If you wish to use a different compiler, you will need to configure the compilerClassName init-param on the JspServlet with the name of the class.

Table 8.1. Understanding Apache JspServlet Parameters

init paramDescriptionDefaultwebdefault.xml


Classpath used for jsp compilation. Only used if org.apache.catalina.jsp_classpath context attribute is not set, which it is in Jetty.



Include debugging info in class file.



Interval in seconds between background recompile checks. Only relevant if ` development=false`.



development=true, recompilation checks occur on each request. See also ` modificationTestInterval`.



Should a source fragment be included in exception messages



Should Jasper issue an error when the value of the class attribute in an useBean action is not a valid bean class



Should Ant fork its Java compiles of JSP pages?




Do you want to keep the generated Java files around?



Should white spaces between directives or actions be trimmed?



Determines whether tag handler pooling is enabled.



Allows specifying the Options class used to configure Jasper. If not present, the default EmbeddedServletOptions will be used.


Support for mapped Files. Generates a servlet that has a print statement per line of the JSP file 



Generation of SMAP info for JSR45 debugging.



Dump SMAP JSR45 info to a file.



Option for generating Strings.



The class-id value to be sent to Internet Explorer when using <jsp:plugin> tags.



The maximum number of JSPs that will be loaded for a web application. If more than this number of JSPs are loaded, the least recently used JSPs will be unloaded so that the number of JSPs loaded at any one time does not exceed this limit. A value of zero or less indicates no limit.



The amount of time in seconds a JSP can be idle before it is unloaded. A value of zero or less indicates never unload.



Directory where servlets are generated. See


If not set, defaults to the Eclipse jdt compiler.


Used if the Eclipse jdt compiler cannot be found on the classpath. It is the classname of a compiler that Ant should invoke.


Target vm to compile for.



Sets source compliance level for the jdt compiler.



Pass through the encoding to use for the compilation.



If development=true, interval between recompilation checks, triggered by a request.



Generate an X-Powered-By response header.




If a JSP compilation fails should the modificationTestInterval be ignored and the next access trigger a re-compilation attempt? Used in development mode only and is disabled by default as compilation may be expensive and could lead to excessive resource usage.


The JSP engine has many configuration parameters. Some parameters affect only precompilation, and some affect runtime recompilation checking. Parameters also differ among the various versions of the JSP engine. This page lists the configuration parameters, their meanings, and their default settings. Set all parameters on the org.apache.jasper.servlet.JspServlet instance defined in the webdefault.xml file.


Be careful: for all of these parameters, if the value you set doesn’t take effect, try using all lower case instead of camel case, or capitalizing only some of the words in the name, as JSP is inconsistent in its parameter naming strategy.

Modifying Configuration

Overriding webdefault.xml

You can make a copy of the {$jetty.home}/etc/webdefault.xml that ships with Jetty, apply your changes, and use it instead of the shipped version. The example below shows how to do this when using the Jetty Maven plugin.


If you are using the Jetty distribution, and you want to change the JSP settings for just one or a few of your webapps, copy the {$jetty.home}/etc/webdefault.xml file somewhere, modify it, and then use a context xml file to set this file as the defaultsDescriptor for your webapp. Here’s a snippet:

 <Configure class=>"org.eclipse.jetty.webapp.WebAppContext">

   <Set name=>"contextPath">/foo</Set>
   <Set name=>"war"><SystemProperty name=>"jetty.home" >default=>"."/>/webapps/foobar.war</Set>
   <Set name=>"defaultsDescriptor">/home/smith/dev/webdefault.xml</Set>


If you want to change the JSP settings for all webapps, edit the {$jetty.home}/etc/webdefaults.xml file directly instead.

Configuring the JSP Servlet in web.xml

Another option is to add an entry for the JSPServlet to the WEB-INF/web.xml file of your webapp and change or add init-params. You may also add (but not remove) servlet-mappings. You can use the entry in {$jetty.home}/etc/webdefault.xml as a starting point.

 <servlet id="jsp">



   <servlet id="my-servlet">

Configuring Async Support

By default, Jetty does not enable async support for the JSP servlet. Configuring the JSP servlet for async is relatively easy - simply define the async-supported parameter as true in either your webdefault.xml or the web.xml for a specific context.

<servlet id="jsp">

Using JSTL Taglibs

The JavaServer Pages Standlard Tag Library (JSTL) is part of the Jetty distribution and is automatically put on the classpath when you select your flavour of JSP. It is also automatically on the classpath for the Jetty Maven plugin, which uses the Apache JSP engine.


If you are using Jetty in an embedded scenario, and you need to use JSTL, then you must ensure that the JSTL jars are included on the container’s classpath - that is the classpath that is the parent of the webapp’s classpath. This is a restriction that arises from the JavaEE specification.

Apache JSP

You will need to put the jars that are present in the {$jetty.home}/lib/apache-jstl directory onto the container’s classpath. The Apache JSP engine will find the JSTL tag definitions inside these jars during startup.

As an efficiency enhancement, you can have jetty examine the JSTL jars to find the tags, and pre-feed them into the Apache JSP engine. This is more efficient, because jetty will only scan the jars you tell it to, whereas the Apache JSP engine will scan every jar, which can be time-consuming in applications with a lot of jars on the container classpath.

To take advantage of this efficiency enhancement, set up the org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern to include a pattern that will match the names of the JSTL jars. The Embedded Examples section includes a worked code example of how to do this. Below is a snippet from the example:


Using JSF Taglibs

The following sections provide information about using JSF TagLibs with Jetty Standalone and the Jetty Maven Plugin.

Using JSF Taglibs with Jetty Distribution

If you want to use JSF with your webapp, you need to copy the JSF implementation Jar (whichever Jar contains the META-INF/*.tld files from your chosen JSF implementation) into Jetty’s shared container lib directory. You can either put them into the lib directory for Apache {$jetty.home}/lib/apache-jsp or put them into {$jetty.home}/lib/ext.

Using JSF Taglibs with Jetty Maven Plugin

You should make your JSF jars dependencies of the plugin and not the webapp itself. For example:


See an error or something missing? Contribute to this documentation at Github!(Generated: 2019-11-25)