| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>Chapter 5. Configuring Contexts</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty"><link rel="up" href="jetty-config-guide.html" title="Part II. Jetty Configuration Guide"><link rel="prev" href="quickstart-webapp.html" title="Quickstart Webapps"><link rel="next" href="configuring-virtual-hosts.html" title="Configuring Virtual Hosts"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><link rel="stylesheet" href="css/highlighter/foundation.css"><script src="js/highlight.pack.js"></script><script> |
| hljs.initHighlightingOnLoad(); |
| </script><link type="text/css" rel="stylesheet" href="css/font-awesome/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small"> |
| Version: 9.3.28.v20191105</span></td><td style="width: 50%"></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 5. Configuring Contexts</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="quickstart-webapp.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a> </td><th width="60%" align="center">Part II. Jetty Configuration Guide<br><a accesskey="p" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></th><td width="20%" align="right"> <a accesskey="n" href="configuring-virtual-hosts.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at |
| <span class="website">www.webtide.com</span></a></h5><p> |
| 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 |
| </p></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="configuring-contexts"></a>Chapter 5. Configuring Contexts</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="section"><a href="configuring-contexts.html#setting-context-path">Setting a Context Path</a></span></dt><dt><span class="section"><a href="configuring-virtual-hosts.html">Configuring Virtual Hosts</a></span></dt><dt><span class="section"><a href="ref-temporary-directories.html">Temporary Directories</a></span></dt><dt><span class="section"><a href="serving-webapp-from-particular-port.html">Serving a WebApp from a Particular Port/Connector</a></span></dt><dt><span class="section"><a href="custom-error-pages.html">Creating Custom Error Pages</a></span></dt><dt><span class="section"><a href="setting-form-size.html">Setting Max Form Size</a></span></dt></dl></div><p>This chapter discusses various options for configuring Jetty contexts.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="setting-context-path"></a>Setting a Context Path</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="configuring-contexts.html#using-embedded-deployment">Using Embedded Deployment</a></span></dt><dt><span class="section"><a href="configuring-contexts.html#usng-the-context-provider">By naming convention</a></span></dt><dt><span class="section"><a href="configuring-contexts.html#using-the-webapp-provider">By Deployer configuration</a></span></dt><dt><span class="section"><a href="configuring-contexts.html#embedding-web-inf-jetty-web.xml-file">Embedding a WEB-INF/jetty-web.xml File</a></span></dt></dl></div><p>The context path is the prefix of a URL path that is used to select the context(s) to which an incoming request is passed. Typically a URL in a Java servlet server is of the format <code class="literal">http://hostname.com/contextPath/servletPath/pathInfo</code>, 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 <span class="emphasis"><em>root</em></span> context. |
| The root context must be configured as <code class="literal">/</code> but is reported as the empty string by the servlet API <code class="literal">getContextPath()</code> method.</p><p>How you set the context path depends on how you deploy the web application (or <code class="literal">ContextHandler</code>).</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="using-embedded-deployment"></a>Using Embedded Deployment</h3></div></div></div><p>If you run Jetty from code as an embedded server (see <a class="link" href="advanced-embedding.html" title="Chapter 21. Embedding">Embedding</a>), setting the context path is a matter of calling the <code class="literal">setContextPath</code> method on the <code class="literal">ContextHandler</code> instance (or <code class="literal">WebAppContext</code> instance).</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="usng-the-context-provider"></a>By naming convention</h3></div></div></div><p>If a web application is deployed using the WebAppProvider of the DeploymentManager without an XML IoC file, then the name of the WAR file is used to set the context path:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">If the WAR file is named myapp.war, then the context will be deployed with a context path of <code class="literal">/myapp</code></li><li class="listitem">If the WAR file is named ROOT.WAR (or any case insensitive variation), then the context will be deployed with a context path of <code class="literal">/</code></li><li class="listitem">If the WAR file is named ROOT-foobar.war ( or any case insensitive variation), then the context will be deployed with a context path of <code class="literal">/</code> and a virtual host of "foobar"</li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="using-the-webapp-provider"></a>By Deployer configuration</h3></div></div></div><p>If a web application is deployed using the <code class="literal">WebAppProvider</code> of the <code class="literal">DeploymentManager</code> with an XML IoC file to configure the context, then the <code class="literal">setContextPath</code> method can be called within that file. |
| For example:</p><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code><Configure class="org.eclipse.jetty.webapp.WebAppContext"> |
| <Set name="contextPath">/test</Set> |
| ... |
| </Configure></code></pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="embedding-web-inf-jetty-web.xml-file"></a>Embedding a WEB-INF/jetty-web.xml File</h3></div></div></div><p>You can also set the context path for webapps by embedding a <code class="literal">WEB-INF/jetty-web.xml</code> file in the WAR, which uses the same XML IoC format as the deployer example above. |
| However this is not the preferred method as it requires the web application to be modified.</p></div></div></div><script type="text/javascript"> |
| SyntaxHighlighter.all() |
| </script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="quickstart-webapp.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a> </td><td width="20%" align="center"><a accesskey="u" href="jetty-config-guide.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right"> <a accesskey="n" href="configuring-virtual-hosts.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Quickstart Webapps </td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></td><td width="40%" align="right" valign="top"> Configuring Virtual Hosts</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout"> |
| See an error or something missing? |
| <span class="callout"><a href="http://github.com/eclipse/jetty.project">Contribute to this documentation at |
| <span class="website"><i class="fa fa-github" aria-hidden="true"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2019-11-05)</i></span></div></p></body></html> |