Jump to: navigation, search

Difference between revisions of "Jetty/Howto/SetContextPath"

< Jetty‎ | Howto
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{Jetty Howto  
 
{{Jetty Howto  
| introduction = The context path is the prefix of a URL path that is used to select the webapplication to which an incoming request is routed.  Typically a URL in a java servlet server is of the format http://hostname.com/contextPath/servletPath/pathInfo, where each of the path elements may be zero or more / separated elements.  If there is no context path, then the context is referred to as the root context.
+
| introduction =  
  
How the context path is set depends on how the webapplication (or ContextHandler) is deployed:
+
{{Jetty Redirect|http://www.eclipse.org/jetty/documentation/current/configuring-contexts.html#setting-context-path}}
 +
 
 +
The context path is the prefix of a URL path that is used to select the web application to which an incoming request is routed.  Typically a URL in a Java servlet server is of the format <nowiki>http://hostname.com/contextPath/servletPath/pathInfo</nowiki>, where each of the path elements may 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):
 
}}
 
}}
  
 
== Embedded Deployment ==
 
== Embedded Deployment ==
If Jetty is run from code as an [[Jetty/Tutorial/Embedding_Jetty|embedded server]] then setting the context path is a matter of calling the setContextPath method on the ContextHandler instance (or WebAppContext instance).  
+
If you run Jetty from code as an [[Jetty/Tutorial/Embedding_Jetty|embedded server]], setting the context path is a matter of calling the <tt>setContextPath</tt> method on the <tt>ContextHandler</tt> instance (or <tt>WebAppContext</tt> instance).  
  
== Context Depoyment ==
+
== Context Deployment ==
If the webapplication/context is deployed from the [[Jetty/Howto/Deploy_Web_Applications|context deployer/provider]] then the contextPath may be set within the context.xml file.  
+
If you deploy the webapplication/context from the [[Jetty/Howto/Deploy_Web_Applications|context deployer/provider]], you set the <tt>contextPath</tt> within the <tt>context.xml</tt> file.  
  
 
   <Configure class="org.eclipse.jetty.webapp.WebAppContext">
 
   <Configure class="org.eclipse.jetty.webapp.WebAppContext">
Line 17: Line 21:
  
 
== Webapp Deployment ==
 
== Webapp Deployment ==
If the webapplication is deployed from the [[Jetty/Howto/Deploy_Web_Applications|webapp deployer/provider]] then by default the name of the WAR file is used to form the context path.  So if the file is called foobar.war, then the context path will be /foobar.  There is a special case for webapps called root.war which are mapped to the root / context.
+
If you deploy the web application from the [[Jetty/Howto/Deploy_Web_Applications|webapp deployer/provider]], by default the name of the WAR file forms the context path.  So if the file is called <tt>foobar.war</tt>, the context path is <tt>/foobar</tt>.  There is a special case for webapps called <tt>root.war</tt> which are mapped to the root / context.
  
The context path may also be set for webapps by embedding a [[Jetty/Reference/jetty-web.xml|WEB-INF/jetty-web.xml]] file in the WAR.  This is not a preferred method.
+
You can also set the context path for webapps by embedding a [[Jetty/Reference/jetty-web.xml|WEB-INF/jetty-web.xml]] file in the WAR.  This is not a preferred method.

Latest revision as of 13:56, 23 April 2013



Introduction


The context path is the prefix of a URL path that is used to select the web application to which an incoming request is routed. Typically a URL in a Java servlet server is of the format http://hostname.com/contextPath/servletPath/pathInfo, where each of the path elements may 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):

Embedded Deployment

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

Context Deployment

If you deploy the webapplication/context from the context deployer/provider, you set the contextPath within the context.xml file.

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

Webapp Deployment

If you deploy the web application from the webapp deployer/provider, by default the name of the WAR file forms the context path. So if the file is called foobar.war, the context path is /foobar. There is a special case for webapps called root.war which are mapped to the root / context.

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.