Table of Contents | Previous | Next | Index | Bookshelf

Programmer's Guide to Servlets


Appendix C
Properties Files

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

servlets.properties

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

Examples of global servlet settings are which servlet to run when the iPlanet Web Server starts up, the reload interval for servlets, and so on. The servlets.properties file also specifies configuration information for individual servlets. Configuration information includes the class name, the classpath, 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 servlets.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 does not have to be the name of the class file for the servlet; it is 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 servlets.properties file:

servlets.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
servlet.demo1.context=context1

rules.properties

The rules.properties file defines servlet virtual path translations. For example, you could set up a mapping so that the URL pointing to /mytest2 invokes the servlet named demo1 in the servlets.properties file. 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 servlets.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_id/mytest2 invokes the servlet at D:/Netscape/Server4/docs/demos/Demo1Servlet.class.

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

rules.properties

# 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

contexts.properties

The contexts.properties file defines contexts, which allow multiple servlets to exchange data and access each other's fields. Contexts are useful for defining virtual servers or for code isolation. If no contexts are defined, the default global context is used for all servlets.

If the context for a servlet is not defined, the servlet belongs to the global context. You can use the same servlet in multiple contexts.

Only the name of a context is required. Any other unspecified properties are inherited from the global context. You can also change the properties of the global context. The comments in the contexts.properties file list the default property values of the global context.

Here is an example of contexts.properties.

contexts.properties

# @(#)contexts.properties (autogenerated)
#
# Contexts Properties:
#
# context.<context_name>.sessionmgr=session manager (some session managers
#            (like MMapSessionManager) can only be instantiated once within the
#            server
# context.<context_name>.sessionmgr.initArgs=list of (name, value) pairs which
#            will represent parameters specific to the session manager
# context.<context_name>.initArgs=list of (name, value) pairs which will be added
#            to this context's attributes
# context.<context_name>.realPathFromRequest=(true|false) tells the server whether
#            to calculate getRealPath based on docRoot of the context or try to go
#            through normal NSAPI steps
# context.<context_name>.respondCookieVersion=(cookie version) tells the server
#            whether to respond with specific cookie version
# context.<context_name>.sessionExpireOnClose(true|false) tells the server to mark
#            session cookies as directed to expire when the user quits the browser
# context.<context_name>.includeTransparency=(true|false) tells the server whether
#            to try to honor setting headers from the included servlet
# context.<context_name>.tempDir=path (forward slashes only) - sets up Servlet API
#            2.2 property for the temporary directory
# context.<context_name>.reloadInterval=seconds - time interval within which the
#            server checks for jsp and servlet files being modified (global context
#            only)
# context.<context_name>.javaBufferSize=bytes (deprecated)
# context.<context_name>.bufferSize=bytes - initial http output stream buffer size
# context.<context_name>.docRoot=path (forward slashes only) - this context
#            document root when not specified - web server's document root will be
#            used (default)
# context.<context_name>.inputStreamLengthCheck=(true|false) - makes
#            ServletInputStream to stop reading data, when Content-Length bytes are
#            read
# context.<context_name>.outputStreamFlushTimer=(seconds|0) - forces the stream to
#            flush the data if certain time elapsed since the last flush; 0 - ignore
#            it
# context.<context_name>.uri=contex_uri_base - additional URI prefix which
#            services as a context base
# context.<context_name>.host=hostname
# context.<context_name>.ip=ip
# context.<context_name>.authdb=name - authentication database
# context.<context_name>.classpath=name - global classpath for this context
# context.<context_name>.signleClassLoader=(true|false) - tells the servlet engine
#            whether to use a single class loader for all servlets in the context
# context.<context_name>.serverName=name - server instance name
# context.<context_name>.contentTypeIgnoreFromSSI=(true|false) - ignore
#            setContentType when invoked from SSI
# context.<context_name>.parameterEncoding=(utf8,none,auto) - advises the web
#            server on how to decode parameters from forms
#
# <context_name>="global" is reserved for the global context. Every new context
#            will inherit initial settings of the global context
#
# Context properties:
# context.global.sessionmgr=com.netscape.server.http.session.SimpleSessionManager
# context.global.sessionmgr.initArgs=
# context.global.initArgs=initial=0
# context.global.realPathFromRequest=false
# context.global.respondCookieVersion=0
# context.global.sessionExpireOnClose=false
# context.global.includeTransparency=true
# context.global.tempDir=/tmp
# context.global.reloadInterval=5
# context.global.javaBufferSize=0
# context.global.bufferSize=4096
# context.global.docRoot=/foo/bar
# context.global.inputStreamLengthCheck=true
# context.global.outputStreamFlushTimer=0
# context.global.uri=/
# context.global.host=
# context.global.ip=
# context.global.authdb=default
# context.global.classpath=
# context.global.singleClassLoader=false
# context.global.contentTypeIgnoreFromSSI=true
# context.global.parameterEncoding=utf8
#
################################# Contexts #############################
context.context1.name=context1


Table of Contents | Previous | Next | Index

Last Updated: 03/01/00 13:50:45

© Copyright © 2000 Sun Microsystems, Inc. Some preexisting portions Copyright © 2000 Netscape Communications Corp. All rights reserved.