<title>Servlet Configuration</title>

Servlet configuration follows the Servlet 2.2 deployment descriptors.
Servlets generally belong in the <var/WEB-INF/classes/> directory of
the web application.

<p/>The mapping from url to servlet is controlled by <a
href='app-config.xtp'>servlet mapping</a> in the application configuration.

<p/>For a complete, working example, see <a href='servlet.xtp'>Servlet</a>
or experiment with the Hello, World demo.

<objsummary/>

<section name='web-app' title=web-app>

<defun name=servlet title='servlet' index='servlet'>
<sum>Defines a servlet alias for later mapping.</sum>

<deftable>
<tr><th>Attribute<th>Description
<tr><td>servlet-name<td>The servlet's name (alias)
<tr><td>servlet-class<td>The servlet's class (defaults to servlet-name)
<tr><td>init-param<td>Initialization parameters
<tr><td>load-on-startup<td>Initializes the servlet when the server starts.
<tr><td>run-at<td>Times to execute the servlet automatically
</deftable>

<p/>The following example defines a servlet alias 'hello'
<example>
&lt;web-app id='/'&gt;

&lt;servlet-mapping url-pattern='/hello.html'
                 servlet-name='hello'/&gt;

&lt;servlet servlet-name='hello'
         servlet-class='test.HelloWorld'&gt;
  &lt;init-param title='Hello, World'/&gt;
&lt;/servlet&gt;

&lt;servlet servlet-name='cron'
         servlet-class='test.DailyChores'&gt;
  &lt;run-at&gt;3:00&lt;/run-at&gt;
&lt;/servlet&gt;

&lt;/web-app&gt;
</example>
</defun>

</section>

<section name='servlet' title='web-app/servlet'>

<defun name=servlet-name title='servlet-name' index='servlet-name'>
<sum>Alias of the servlet</sum>
</defun>

<defun name=servlet-class title='servlet-class' index='servlet-class'>
<sum>Class of the servlet</sum>  The CLASSPATH for servlets includes
the WEB-INF/classes directory and all jars in the WEB-INF/lib directory.
</defun>

<defun name=init-param title='init-param' index='init-param'>
<sum>Initializes servlet variables.</sum>  <code/servlet-param/>
defines initial values for <code/getServletConfig().getInitParameter("foo")/>.

The full servlet 2.2 syntax is supported and allows a simple shortcut
<example>
&lt;web-app id='/'&gt;

&lt;servlet servlet-name='test.HelloWorld'&gt;
  &lt;init-param foo='bar'/&gt;

  &lt;init-param&gt;
    &lt;param-name&gt;baz&lt;/param-name&gt;
    &lt;param-value&gt;value&lt;/param-value&gt;
  &lt;/init-param&gt;
&lt;/servlet&gt;

&lt;/web-app>
</example>
</defun>

<defun name=load-on-startup title='load-on-startup' index='load-on-startup'>
<sum>If present, starts the servlet when the server starts.</sum>
<example>
&lt;web-app id='/'>

&lt;servlet servlet-name='hello'
         servlet-class='test.HelloWorld'&gt;
  &lt;load-on-startup/&gt;
&lt;/servlet&gt;

&lt;/web-app&gt;
</example>
</defun>

<defun name=run-at title='run-at' index='run-at' version='Resin 1.1'>
<sum>If present, calls the servlet's <var/service()/> method
at the specified times.</sum>
&lt;run-at> lets servlet writers execute periodic tasks without worrying
about creating a new Thread.

<p/>The value is a list of 24-hour times when the
servlet should be automatically executed.  To run the servlet every 6
hours, you could use

<example>
&lt;servlet servlet-name='test.HelloWorld'&gt;
  &lt;run-at&gt;0:00, 6:00, 12:00, 18:00&lt;/run-at&gt;
&lt;/servlet&gt;
</example>

<p/>If the hour is omitted, the servlet runs every hour at the
specified minute.  To run the server every 15 minutes, you could use:

<example>
&lt;servlet servlet-name='test.HelloWorld'&gt;
  &lt;run-at&gt;:00, :15, :30, :45&lt;/run-at&gt;
&lt;/servlet&gt;
</example>
</defun>

</section>
