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 4. Configuring Contexts

Table of Contents

Setting a Context Path
Setting Context Path to / (root)
Creating Custom Error Pages
Serving a WebApp from a Particular Port

This chapter discusses various options for configuring Jetty contexts.

Setting a Context Path

The context path is the prefix of a URL path that Jetty uses to select the web application to which it routes an incoming request. Typically a URL in a Java servlet server is of the format http://hostname.com/contextPath/servletPath/pathInfo, where each of the path elements can be zero or more / separated elements. If there is no context path, the context is referred to as the root context.

How you set the context path depends on how you deploy the web application (or ContextHandler):

Using Embedded Deployment

If you run Jetty from code as an embedded server (see ???), setting the context path is a matter of calling the setContextPath method on the ContextHandler instance (or WebAppContext instance).

Using the Context Provider

If you deploy the web application/context by Using the Context Provider, you set the contextPath within the context.xml file.


      <Configure class="org.eclipse.jetty.webapp.WebAppContext">
      <Set name="contextPath">/foo</Set>...</Configure>
    
    

Using the Webapp Provider

If you deploy the web application by Using the WebApp Provider, by default the name of the WAR file forms the context path. So if the filename is foobar.war, the context path is /foobar. There is a special case for webapps called root.war which are mapped to the root / context. See Setting Context Path to / (root).

Embedding a WEB-INF/jetty-web.xml File

You can also set the context path for webapps by embedding a WEB-INF/jetty-web.xml file in the WAR. This is not a preferred method.

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