Difference between revisions of "Jetty/Howto/SetContextPath"

From Eclipsepedia

< Jetty‎ | Howto
Jump to: navigation, search
(New page: {{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 s...)
 
Line 7: Line 7:
 
== 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 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).  
 +
 +
== Context Depoyment ==
 +
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.
 +
 +
  <Configure class="org.eclipse.jetty.webapp.WebAppContext">
 +
    <Set name="contextPath">/foo</Set>
 +
    ...
 +
  </Configure>
  
 
== Webapp Deployment ==
 
== Webapp Deployment ==
If the webapplication is run from the [[Jetty/Howto/Deploy_Web_Applications#Webapps_Deployment|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 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.
  
 
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.
 
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.
 
 
 
== Context Depoyment ==
 

Revision as of 00:11, 24 March 2011



Contents

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.

How the context path is set depends on how the webapplication (or ContextHandler) is deployed:

Embedded Deployment

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

Context Depoyment

If the webapplication/context is deployed from the context deployer/provider then the contextPath may be set within the context.xml file.

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

Webapp Deployment

If the webapplication is deployed from the 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.

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