The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Servlets
Lesson: The servletrunner Utility

Servlet Properties

Properties are key-value pairs used for the configuration, creation and initialization of a servlet. For example, in JSDK2.0 servlet.catalog.code=CatalogServlet is a property whose key is servlet.catalog.code and whose value is CatalogServlet. In JSDK2.1 that same property would be named catalog.code=CatalogServlet is a property whose key is catalog.code and whose value is CatalogServlet.

Using properties requires you to name your servlet. (The string catalog in the property names above is the catalog servlet's name.) The servlet name enables the servlet-running utilities to associate properties with the correct servlets. It is also the name that clients will use when they access your servlet.

The JSDK servlet running utilities have two properties for servlets. They associate the name that you choose for your servlet with:


 

The Servlet Class

This section uses the shorter JSDK2.1 property names. If you are using JSDK2.0, add "servlet." to the beginning of the property name.

The property that associates the name that you choose for your servlet with the servlet class is name.code. The value of the property is the servlet's full class name, including its package. For example if the duke's bookstore classes were in an examples.bookstore package, the catalog servlet would have this property:

    catalog.code=examples.bookstore.CatalogServlet

The name.code property names your servlet by associating a name (in the example, catalog) with a class (in the example, examples.bookstore.CatalogServlet).
 

Initialization Parameters

The value of the name.initParams property holds a JSDK2.1 servlet's initialization parameters. For JSDK2.0 servlets, the property name isservlet.name.initArgs. (This section uses the JSDK2.1 property names.)

The syntax of a single initialization 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 bookstore servlet took the name of the initial HTML file as a parameter, the servlet's initial argument might look like this:

    servlet.bookdb.initArgs=\
        mainFile=examples/bookstore/Bookstore.html

Multiple initialization parameters are specified as a comma-separated list. For example, if the book detail servlet got its book information by connecting to a real database, its initial arguments might look like this:

    bookdetails.initParams=\
	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 servlets.properties in JSDK2.1 and servlet.properties in JSDK2.0. The file holds the properties for all the servlets that the servlet-running utility 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
    bookstore.code=BookStoreServlet
    
    # View all the books in the bookstore
    catalog.code=CatalogServlet
    
    # Show information about a specific book
    bookdetails.code=BookDetailServlet
    
    # See the books that you've chosen to buy
    showcart.code=ShowCartServlet
    
    # Collects information for buying the chosen books
    cashier.code=CashierServlet
    
    # Provide a receipt to the user who's bought books
    receipt.code=ReceiptServlet
    

Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form