Programmer's Guide to Servlets in Enterprise Server 4.0
Table of Contents | Previous | Next | Index

Programmer's Guide to Servlets in Enterprise Server 4.0


Appendix C
servlets.properties and rules.properties

This appendix discusses the purpose and use of the files servlet.properties and rules.properties, which reside in the directory server_id/config.

servlet.properties

The servlet.properties file defines global servlet settings and the list of servlets in the system.

The servlet.properties file specifies global settings for servlets, such as a servlet to run when the Enterprise server starts up, the reload interval for servlets, and so on. It also specifies configuration information for individual servlets. Configuration information includes the class name, the class path and any input arguments required by the servlet.

If you want to specify a virtual path translation for a servlet, the servlet must be configured in the servlet.properties file.

You can specify configuration information for servlets either by using the Servlets>Configure Servlet Attributes page in the Server Manager interface or by editing servlets.properties directly. Whenever you make a change in the Servlets>Configure Servlet Attributes page in the Server Manager interface, the system automatically updates servlets.properties.

When specifying attributes for a servlet, you specify a name parameter for the servlet. This name is not the name of the class file for the servlet but is instead an internal identifier for the servlet. You specify the name of the class file as the value of the code parameter.

Here is a sample servlet.properties file:

servlet.properties 
# Servlets Properties
# servlets to be loaded at startup
servlets.startup= hello
# the reload interval for dynamically-loaded servlets and JSPs
# (default is 10 seconds)
servlets.config.reloadInterval=5
# the default document root,
# needed so ServletContext.getRealPath will work
servlets.config.docRoot=E:/Netscape/Server4/docs
# the session manager servlets.sessionmgr=com.netscape.server.http.session.SimpleSessionManager
# tracker servlet
servlet.tracker.code=MyTrackerServlet
servlet.tracker.classpath=D:/Netscape/Server4/docs/servlet
# demo1 servlet
servlet.demo1.code=Demo1Servlet
servlet.demo1.classpath=D:/Netscape/Server4/docs/demos
servlet.demo1.initArgs=a1=0,b1=3456

rules.properties

The rules.properties files defines servlet virtual path translations. For example, you could set up a mapping so that the URL pointing to /index.html invokes the servlet /servlet/runintro.class. You can specify virtual paths for your servlets either by setting parameters in the Servlets>Configure Servlet Virtual Path Translation page of the Server Manager interface or by specifying the paths in the rules.properties file.

Note that the "name" associated with the servlet in servlets.properties is used in the file rules.properties -- the class name of the servlet does not show up in rules.properties. For example, the following lines in servlet.properties associate the servlet name demo1 with the servlet class file Demo1Servlet.class in the directory D:/Netscape/Server4/docs/demos.

# in servlets.properties
# demo1 servlet
servlet.demo1.code=Demo1Servlet
servlet.demo1.classpath=D:/Netscape/Server4/docs/demos
The following line in rules.properties defines a servlet virtual path translation such that the URL http://server-name/mytest2 invokes the servlet at D:/Netscape/Server4/docs/demos/Demo1Servlet.class.

/mytest2=demo1
Here is an example of rules.properties.

rules.properties (defines URL name space for each of the servlets):

# Servlet rules properties 
# This file specifies the translation rules for invoking servlets.
# The syntax is:
# /virtual-path=servlet-name
# where virtual-path is the virtual path used to invoke the servlet,
# and servlet-name is the name of the servlet as specified in
# servlets.properties.
# Surrounding white space is ignored.
# The ordering of the rules is not important, as the longest
# match is always used first.
/mytest1=tracker
/mytest2=demo1


Table of Contents | Previous | Next | Index

Last Updated: 08/12/99 12:39:30

Copyright © 1999 Netscape Communications Corp. All rights reserved.