Dashboard > Jetty > ... > Jetty Documentation > Static Content
Static Content Log In | Sign Up   View a printable version of the current page.

Added by Jan Bartel , last edited by Jukka Koivusalo on Apr 11, 2007  (view change)
Labels: 
(None)

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

Serving static content

If you just want to serve simple static content without needing to have an entire web application, there are a couple of alternatives.

Using a servlet Context and DefaultHandler

There is an example of doing this in the jetty distribution in the $JETTY-HOME/contexts/javadoc.xml file. Here it is:

<Configure class="org.mortbay.jetty.servlet.Context">
  <Set name="contextPath">/javadoc</Set>
  <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/javadoc/</Set>
  <Call name="addServlet">
    <Arg>org.mortbay.jetty.servlet.DefaultServlet</Arg>
    <Arg>/</Arg>
  </Call>
</Configure>

The Context is used to match urls of the form /javadoc/*, and to set up the location of the static resources, which in this case is the directory $JETTY-HOME/javadoc. The DefaultHandler serves the resources.

You would choose this method of serving static content if you want to be able to use Servlets and/or take advantage of the other features of the DefaultServlet.

Using a ContextHandler and a ResourceHandler

Alternatively, for a slightly more lightweight and simple solution you can use a ContextHandler and a ResourceHandler. Here is an example:

<Configure class="org.mortbay.jetty.handler.ContextHandler">
   <Set name="contextPath">/javadoc</Set>
   <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/javadoc</Set>
   <Call name="addHandler">
       <Arg>
           <New class="org.mortbay.jetty.handler.ResourceHandler"/>
       </Arg>
   </Call>
</Configure>

The ContextHandler is used to match urls of the form /javadoc/*, and to set up the location of the static resources (again $JETTY-HOME/javadoc). The ResourceHandler serves the resources.

Site running on a free Atlassian Confluence Open Source Project License granted to The Codehaus. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.2 Build:#919 Nov 26, 2007) - Bug/feature request - Contact Administrators