The JavaTM Tutorial

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Trail: Servlets
Lesson: Running Servlets

## Configuring JSDK Servlets

> You configure servlet applications that run on the JSDK 2.1 server by specifying properties. Properties are key-value pairs used for the configuration, creation, and initialization of a servlet. For example, `catalog.code=CatalogServlet` is a property whose key is `catalog.code` and whose value is `CatalogServlet`. Properties are stored in a text file with a default name of `servlets.properties`. The file holds the properties for all the servlets that the servlet-running utility will run.

> 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 server has two properties for servlets. They associate the name that you choose for your servlet with:

> - The class name of the servlet
> - Any initialization parameters that the servlet requires

> ## The Servlet Class

> 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 servlet's initialization parameters.

> 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:

>        bookdb.initparams=\
>           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

> Here is the servlets.properties file for the Duke's Bookstore example.

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.