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

Added by Jan Bartel , last edited by Jan Bartel on Jan 30, 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

What is webdefault.xml?

The webdefault.xml is a file which is applied to a web application BEFORE the application's own WEB-INF/web.xml. It is used to save a web application from having to define a lot of house-keeping and container-specific elements in their own web.xml files.

There is a copy of the webdefault.xml file supplied with jetty in $(jetty.home)/etc/webdefault.xml.

Configuration contained in webdefault.xml

Session configuration

<context-param>
    <param-name>org.mortbay.jetty.servlet.SessionDomain</param-name>
    <param-value>127.0.0.1</param-value>
  </context-param>

  <context-param>
    <param-name>org.mortbay.jetty.servlet.SessionPath</param-name>
    <param-value>/</param-value>
  </context-param>

  <context-param>
    <param-name>org.mortbay.jetty.servlet.MaxAge</param-name>
    <param-value>-1</param-value>
  </context-param>

  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>

JSP configuration

<servlet id="jsp">
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    <init-param>
        <param-name>logVerbosityLevel</param-name>
        <param-value>DEBUG</param-value>
    </init-param>
    <init-param>
        <param-name>fork</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>xpoweredBy</param-name>
        <param-value>false</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>*.jsp</url-pattern>
    <url-pattern>*.jspf</url-pattern>
    <url-pattern>*.jspx</url-pattern>
    <url-pattern>*.xsp</url-pattern>
    <url-pattern>*.JSP</url-pattern>
    <url-pattern>*.JSPF</url-pattern>
    <url-pattern>*.JSPX</url-pattern>
    <url-pattern>*.XSP</url-pattern>
  </servlet-mapping>

Mime configuration

<mime-mapping>
    <extension>mysuffix</extension>
    <mime-type>mymime/type</mime-type>
  </mime-mapping>

Default Servlet for static content

<servlet>
    <servlet-name>default</servlet-name>
    <servlet-class>org.mortbay.jetty.servlet.DefaultServlet</servlet-class>
    <init-param>
      <param-name>acceptRanges</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>dirAllowed</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>redirectWelcome</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>maxCacheSize</param-name>
      <param-value>2000000</param-value>
    </init-param>
    <init-param>
      <param-name>maxCachedFileSize</param-name>
      <param-value>254000</param-value>
    </init-param>
    <init-param>
      <param-name>maxCachedFiles</param-name>
      <param-value>1000</param-value>
    </init-param>
    <init-param>
      <param-name>useFileMappedBuffer</param-name>
      <param-value>true</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>

  <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>

Dynamic Invocation

<servlet>
    <servlet-name>invoker</servlet-name>
    <servlet-class>org.mortbay.jetty.servlet.Invoker</servlet-class>
    <init-param>
      <param-name>verbose</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>nonContextServlets</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>dynamicParam</param-name>
      <param-value>anyValue</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>

  <servlet-mapping> <servlet-name>invoker</servlet-name> <url-pattern>/servlet/*</url-pattern> </servlet-mapping>

How to customize webdefault.xml

Jetty Standalone

You can modify any of the settings inside the version of webdefault.xml shipped in the jetty distribution and apply it to an individual web application by using:

<Configure class="org.mortbay.jetty.webapp.WebAppContext">
  ...
  <Set name="defaultsDescriptor">/my/path/to/webdefault.xml</Set>
  ...
</Configure>

Which equivalently in code is:

import org.mortbay.jetty.webapp.WebAppContext;

...

WebAppContext wac = new WebAppContext();
...
//Set up the absolute path to the custom webdefault.xml.
//Alternatively, you can use a classloader to find the
//resource representing your custom webdefault.xml
wac.setDefaultsDescriptor("/my/path/to/webdefault.xml");
...

If you want to apply the same custom webdefault.xml to a number of webapps, then supply the path to the file to the hot deployer or the static deployer:

<New class="org.mortbay.jetty.deployer.WebAppDeployer">
    ...
    <Set name="defaultsDescriptor">/my/path/to/webdefault.xml</Set>
</New>

Jetty Maven Plugin

Similarly, for the maven jetty plugin, you provide a customized webdefault.xml file for your webapp by:

<project>
  ...
  <plugins>
    ...
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <configuration>
         ...
          <webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
         ...
        </configuration>
      </plugin>
   </plugins>
</project>

You can find more information on configuring the maven jetty plugin here.

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
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