|[Back to Index]|
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
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:
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:
Specify the classname for a servlet with this line:
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
If this tag is used for a servlet, then the
The syntax for this property is:
<servlet name>.aliasFor=<aliased servlet name>
These parameters are accessed in the usual manner from a servlet's
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
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:
default.mapping=/ default.class=com.qindesign.servlet.DefaultServlet default.initParams=canBrowseDirs=true default.loadOnStartup=true
A few notes of explanation are worthwhile:
© 2002-2007 Shawn Silverman