Servlet Configuration Properties

This document describes how to configure servlets. The conventions used are the same as those defined in Sections 10 & 13 of the Servlet 2.2 Specification ("Mapping Requests to Servlets" & "Deployment Descriptor").

The server looks for a configuration file specified by the servlet.propsFile property. (In the Servlet Properties section of the server configuration file.) Note that a smaller file takes less time to load, so if there are few unnecessary lines in the file, then the server will start faster. For example, references to unused servlets can be safely removed.

It should be stated first that there is only one servlet context, and that all the servlets defined here are within this scope. This means two things. First, that each servlet shares the same context initialization parameters and attributes, and second, that each servlet is known to all others via a named request dispatcher.

There are five subsections:

Specifying a Mapping

Specifying a mapping is as simple as declaring:

<servlet name>.mapping=<path>

where <path> is the URL path used to access the servlet and <servlet name> is an internal pointer to the servlet object. The name can be anything you like, and does not have to match the servlet's classname. Note that servlets can be accessed by their name from a "named request dispatcher".

All the rules for finding a particular servlet based on the requested URI follow those outlined in Section 10 "Mapping Requests to Servlets" in the specification. Additionally, there is a default servlet provided for those paths that do not map to any servlet.

All servlets must have a mapping, even if it is blank. Those that don't are ignored by the servlet container. Blank mappings make the servlet only accessible to a RequestDispatcher, from inside another servlet.

For example, say you want to access MyUsefulServlet via "http://snap_address/servlet/useful". The proper mapping would be:



Servlet Code

Specify the classname for a servlet with this line:

<servlet name>.class=<classname>

where <classname> is the full classname of a class that implements the javax.servlet.Servlet interface. (Note that by subclassing javax.servlet.http.HttpServlet, you are still meeting this condition.)

It is possible for more than one servlet to share the same class. If the same class is being used by more than one servlet, then a new instance will be created for each.

For example, the class for MyUsefulServlet may be:



There is a second way to specify that a servlet uses the same class as another. Using the .aliasFor tag specifies that the servlet share the same instance of the class used by the aliased servlet.

If this tag is used for a servlet, then the .class and .loadOnStartup tags are ignored.

The syntax for this property is:

<servlet name>.aliasFor=<aliased servlet name>

where <aliased servlet name> is the servlet whose class instance is shared by <servlet name>.


Initialization Parameters

Use the .initParams tag to specify any initialization parameters for the servlet. Each parameter is of the form <name>=<value>, and separated by commas:

<servlet name>.initParams=<name1>=<value1>,<name2>=<value2>,...

For example:


These parameters are accessed in the usual manner from a servlet's ServletConfig object. Please consult the servlet documentation for more details.


Servlet Creation

Servlets are normally loaded and initialized when they are first used. To load and initialize a servlet when the server starts, however, simply specify a value of true for the .loadOnStartup tag:

<servlet name>.loadOnStartup=true

Loading a servlet on server startup is useful when certain tasks need to be executed at this time. For example, perhaps a PPP connection over a modem needs to be established to connect the SNAP to the network. Or, perhaps a servlet takes a while to initialize; it may be best to load it when the server starts to avoid any delays when accessing it for the first time.


Configuring the Default Servlet

The "default servlet" is the servlet that gets called when no other servlet can be found that matches the requested resource. For example, if no servlet mapping has been specified for /my/requested/resource, then a request for this is passed to the default servlet.

The default servlet that is included in Tynamo™ has two configuration options that allow directory listings to be viewed. In order to set these, the servlet must be included in the servlet properties file like this:


A few notes of explanation are worthwhile:

  • The name of the servlet is "default" in the above configuration, but can be anything you like. The servlet container knows this is the default servlet because of a mapping value of '/', not because of the name.
  • The directory browsing option is configured with the "canBrowseDirs" init. parameter.
  • The file system browsing option is configured with the "canBrowseFS" init. parameter. If set to "true", then the servlet will allow a browser to view the contents of the file system outside of the server root directory.
  • The "loadOnStartup" option is not required, and will default to a value of false. It is often the case that a web server will be used at least once for loading a file (eg. HTML), so loading this servlet on startup will speed up the first access.
  • It is possible to use another class for the default servlet, but it may not recognize the same configuration options.


If this is set to true then the servlet will allow a browser to view the directory contents of those directories that do not contain a welcome file (usually index.html).

The default is false.


If this is set to true then the servlet will allow a browser to view the contents of the filesystem outside of the server root directory.

For example, requests that include "..", and that go outside of this area, are possible.

The default is false.