Previous | Next | Trail Map | Servlets | The servletrunner Utility

Setting Servlet Properties

Properties are key-value pairs used for the configuration, creation and initialization of a servlet. For example, servlet.catalog.code=CatalogServlet is a property whose key is servlet.catalog.code and whose value is CatalogServlet.

The servletrunner utility has two properties for servlets:


 

The code Property

The value of the servlet.name.code property is the servlet's full class name, including its package. For example:

    servlet.bookdb.code=database.BookDBServlet

The servlet.name.code property names your servlet by associating a name (in the example, bookdb) with a class (in the example, database.BookDBServlet).
 

The initargs Property

The value of the servlet.name.initArgs property holds the servlet's initialization parameters. The syntax of a single parameter is parameterName=parameterValue. The entire property (the entire key-value pair) must be a single logical line. For readability, you can use the backquote syntax to allow the property to span multiple lines in the file. For example, if the database servlet read the data from a file, the servlet's initial argument might look like this:

    servlet.bookdb.initArgs=\
        dbfile=servlets/DatabaseData

Multiple initialization parameters are specified as a comma-delimited list. For example, if the database servlet connected to a real database, its initial arguments might look like this:

    servlet.bookdb.initArgs=\
	user=duke,\
	password=dukes_password,\
	url=fill_in_the_database_url

 

The Property File

Properties are stored in a text file with a default name of servlet.properties. (You can specify another name when you start servletrunner.) The file holds the properties for all the servlets that servletrunner will run. Here is the servlet.properties file for the Duke's Bookstore example:

    # This file contains the properties for the Duke's Bookstore servlets.

    # Duke's Book Store -- main page
    servlet.bookstore.code=BookStoreServlet
    
    # The servlet that manages the database of books
    servlet.bookdb.code=database.BookDBServlet
    
    # View all the books in the bookstore
    servlet.catalog.code=CatalogServlet
    
    # Show information about a specific book
    servlet.bookdetails.code=BookDetailServlet
    
    # See the books that you've chosen to buy
    servlet.showcart.code=ShowCartServlet
    
    # Collects information for buying the chosen books
    servlet.cashier.code=CashierServlet
    
    # Provide a receipt to the user who's bought books
    servlet.receipt.code=ReceiptServlet
    


Previous | Next | Trail Map | Servlets | The servletrunner Utility