Jetty Logo
Contact the core Jetty developers at www.webtide.com

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 11. Session Management

Table of Contents

Setting Session Characteristics
Using Persistent Sessions
Session Clustering with a Database
Session Clustering with MongoDB

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 11.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.CheckingRemoteSessionIdEncodingfalse 

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:


<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5">
  ...
  <context-param>
    <param-name>org.eclipse.jetty.servlet.SessionCookie</param-name>
    <param-value>XSESSIONID</param-value>
  </context-param>
  <context-param>
    <param-name>org.eclipse.jetty.servlet.SessionIdPathParameterName</param-name>
    <param-value>xsessionid</param-value>
  </context-param>
  ...
</web-app>

        

Web Application Examples

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


<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/test</Set>
  <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test</Set>
 
  ...
 
  <Call name="setInitParameter">
        <Arg>org.eclipse.jetty.servlet.SessionCookie</Arg>
        <Arg>XSESSIONID</Arg>
  </Call>
  <Call name="setInitParameter">
        <Arg>org.eclipse.jetty.servlet.SessionIdPathParameterName</Arg>
        <Arg>xsessionid</Arg>
  </Call>
</Configure>

        

SessionManager Examples

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


<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/test</Set>
  <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test</Set>
 
   ...

  <Get name="sessionHandler">
     <Set name="sessionManager">
         <New class="org.eclipse.jetty.server.session.HashSessionManager">
            <Set name="sessionCookie">XSESSIONID</Set>
            <Set name="sessionIdPathParameterName">xsessionid</Set>
         </New>
     </Set>
  </Get>
</Configure>

        

See an error or something missing? Contribute to this documentation at Github!