Jetty Logo
Version: 9.3.1-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 from 1 day to full product delivery

Chapter 10. Session Management

Table of Contents

Setting Session Characteristics
Using Persistent Sessions
Session Clustering with a Database
Session Clustering with MongoDB
Session Clustering with Infinispan
Session Clustering with Google Cloud Datastore

Setting Session Characteristics

To modify the session characteristics of a web application, you can use the following parameters, applying them as in one of the example configurations:

Using Init Parameters

Use these parameters to set session characteristics.

Table 10.1. Init Parameters

Context ParameterDefault ValueDescription
org.eclipse.jetty.servlet.SessionCookieJSESSIONIDSession cookie name defaults to JSESSIONID, but can be set for a particular webapp with this context param.
org.eclipse.jetty.servlet.SessionIdPathParameterNamejsessionidSession URL parameter name. Defaults to jsessionid, but can be set for a particular webapp with this context param. Set to "none" to disable URL rewriting.
org.eclipse.jetty.servlet.SessionDomain-Session Domain. If this property is set as a ServletContext param, then it is used as the domain for session cookies.If it is not set, then no domain is specified for the session cookie.
org.eclipse.jetty.servlet.SessionPath-Session Path. If this property is set as a ServletContext param, then it is used as the path for the session cookie. If it is not set, then the context path is used as the path for the cookie.
org.eclipse.jetty.servlet.MaxAge-1Session Max Age. If this property is set as a ServletContext param, then it is used as the max age for the session cookie. If it is not set, then a max age of -1 is used.
org.eclipse.jetty.servlet.CheckingRemoteSessionIdEncodingfalseIf true, Jetty will add JSESSIONID parameter even when encoding external urls with calls to encodeURL(). False by default.

Applying Init Parameters

The following sections provide examples of how to apply the init parameters.

Context Parameter Example

You can set these parameters as context parameters in a web application's WEB-INF/web.xml file:

Web Application Examples

You can configure init parameters on a web application, either in code, or in a Jetty context xml file equivalent:

SessionManager Examples

You can configure init parameters directly on a SessionManager instance, either in code or the equivalent in xml:

Using Servlet 3.0 Session Configuration

With the advent of Servlet Specification 3.0 there are new APIs for configuring session handling characteristics. What was achievable before only via jetty-specific init-parameters can now be achieved in a container-agostic manner either in code, or via web.xml.


The javax.servlet.SessionCookieConfig class can be used to set up session handling characteristics. For full details, consult the javadoc.

Here's an example of how you use it: this is a ServletContextListener that retrieves the SessionCookieConfig and sets up some new values for it when the context is being initialized:

You can also use web.xml to configure the session handling characteristics instead: here's an example, doing exactly the same as we did above in code:


In addition to the configuration of session cookies, since Servlet 3.0 you can also use the javax.servlet.SessionTrackingMode to configure session tracking.

To determine what are the default session tracking characteristics used by the container, call:

This returns a java.util.Set of javax.servlet.SessionTrackingMode. The default session tracking modes for Jetty are:

To see which session tracking modes are actually in effect for this Context, the following call returns a java.util.Set of javax.servlet.SessionTrackingMode:

To change the session tracking modes, call:

You may also set the tracking mode in web.xml, eg:

See an error or something missing? Contribute to this documentation at Github!(Generated: 2015-11-26T01:01:10+00:00)