Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

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

Code Block
xml
xml
<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

Code Block
xml
xml
<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

Code Block
xml
xml
<mime-mapping>
    <extension>mysuffix</extension>
    <mime-type>mymime/type</mime-type>
  </mime-mapping>


Default Servlet for static content

Code Block
xml
xml
<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

Code Block
xml
xml
<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:

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


Which equivalently in code is:

Code Block
java
java
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:

Code Block
xml
xml
<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:

Code Block
xml
xml
<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