blob: 7134eadc465537fb96748bae10c42863dab68916 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter&nbsp;5.&nbsp;Configuring Contexts</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><meta name="keywords" content="jetty, servlet-api, cometd, http, spdy, eclipse, maven, java, software"><link rel="home" href="index.html" title="Jetty : The Definitive Reference"><link rel="up" href="configuring.html" title="Part&nbsp;II.&nbsp;Jetty Configuration Guide"><link rel="prev" href="setting-port80-access.html" title="Setting Port 80 Access for a Non-Root User"><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"><script type="text/javascript" src="js/shCore.js"></script><script type="text/javascript" src="js/shBrushJava.js"></script><script type="text/javascript" src="js/shBrushXml.js"></script><script type="text/javascript" src="js/shBrushBash.js"></script><script type="text/javascript" src="js/shBrushJScript.js"></script><script type="text/javascript" src="js/shBrushSql.js"></script><script type="text/javascript" src="js/shBrushProperties.js"></script><script type="text/javascript" src="js/shBrushPlain.js"></script><link type="text/css" rel="stylesheet" href="css/shCore.css"><link type="text/css" rel="stylesheet" href="css/shThemeEclipse.css"><link type="text/css" rel="stylesheet" href="css/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.0.6.v20130930</span></td><td style="width: 50%"><script type="text/javascript"> (function() {
var cx = '016459005284625897022:obd4lsai2ds';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script><gcse:search></gcse:search></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&nbsp;5.&nbsp;Configuring Contexts</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="setting-port80-access.html"><i class="icon-chevron-left"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;II.&nbsp;Jetty Configuration Guide<br><a accesskey="p" href="index.html"><i class="icon-home"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="configuring-virtual-hosts.html">Next <i class="icon-chevron-right"></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/support.jsp">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 from 1 day to full product delivery
</p></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="configuring-contexts"></a>Chapter&nbsp;5.&nbsp;Configuring Contexts</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><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="configuring-webapps.html">Configuring WebAppContexts</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><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="filename">
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 "/" but is
reported as the empty string by the servlet API getContextPath()
method.</p><p>How you set the context path depends on how you deploy the web
application (or ContextHandler):</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&nbsp;19.&nbsp;Embedding">Embedding</a>), setting the context path
is a matter of calling the <code class="code">setContextPath</code> method on the
<code class="code">ContextHandler</code> instance (or <code class="code">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
DeployentManager 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" type="disc"><li class="listitem"><p>If the WAR file is named myapp.war, then the context will be
deployed with a context path of /myapp</p></li><li class="listitem"><p>If the WAR file is named ROOT.WAR (or any case insensitive
variation), then the context will be deployed with a context path of
/</p></li><li class="listitem"><p>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 / and a virtual host of "foobar"</p></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 WebAppProvider of the the
DeploymentManager with an XML IoC file to configure the context, then the
setContextPath method can be called within that file. For example:</p><script type="syntaxhighlighter" class="brush: xml;toolbar: false">
<![CDATA[
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/test</Set>
...
</Configure>
]]>
</script></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="filename">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="setting-port80-access.html"><i class="icon-chevron-left"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="configuring.html"><i class="icon-chevron-up"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="configuring-virtual-hosts.html">Next <i class="icon-chevron-right"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Setting Port 80 Access for a Non-Root User&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="icon-home"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;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/jetty-project/jetty-documentation">Contribute to this documentation at
<span class="website"><i class="icon-github"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2013-10-30T13:20:21-05:00)</i></span></div></p><script 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" type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1149868-7']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></body></html>