Previous Next Contents Index


Controlling Applications with Servlets

This chapter describes how to create effective Java servlets to control interactions in Netscape Application Server applications.

Servlets, like applets, are reusable Java applications. Unlike applets, however, servlets run on an application server or web server rather than in a web browser.

In NAS, servlets make up the presentation logic of an application by acting as a central dispatcher for your application by processing form input, invoking business logic components by accessing Enterprise JavaBeans, and formatting page output using JSPs. Servlets control the application's flow from one user interaction to the next by generating content in response to a request from your user.

This chapter contains the following sections:


Introducing Servlets
NAS servlets are based on the Servlet API specification. All specifications are accessible from installdir/nas/docs/index.htm, where installdir is the location in which you installed NAS.

There are three kinds of servlets: those that adhere strictly to the specification; those that take advantage both of the specification and additional NAS features; and those that adhere to the specification in non-NAS environments, but that take advantage of NAS features if they are available. This chapter describes standard servlets as well as the NAS features that augment the standards, and enables you to make the best choice for your intended deployment scenario.

The fundamental characteristics of servlets are as follows:

NAS offers several features through NAS-specific APIs that enable your applications to take programmatic advantage of specific features of the NAS environment. For more information, see Accessing Optional NAS Features.

Servlets in NAS Applications When a user of your application clicks a button on one of your application's pages, the information that the user entered on the page is sent to a servlet. The servlet processes the incoming data and orchestrates a response by generating content, often through the use of business logic components (Enterprise JavaBeans). Once the content is generated, the servlet creates a response page, usually by forwarding the newly generated content to a JavaServer Page (JSP). The response is delivered back the client, which sets up the next user interaction.

The following illustration shows the life cycle of a single user interaction, the execution of a single servlet.

  1. Process incoming request from client
  2. Generate content
  3. Create a response
For a more detailed description of a servlet's life cycle, see How Servlets Work.

How Servlets Work This section describes the basic ingredients of all servlets. It shows how NAS runs servlets from the perspective of the server itself. Servlets exist in the NAS Java server process and are managed by an object called the servlet engine. The servlet engine is an internal object that handles all servlet metafunctions. These functions include instantiation, initialization, destruction, access from other components, and configuration management.

Types of Servlets
Servlets must implement the interface javax.servlet.Servlet. There are two main types of servlets:

For both types of servlets, you can implement the constructor method init() and/or the destructor method destroy() if you need to initialize or deallocate resources.

All servlets must implement a service() method. This method is responsible for handling requests made to the servlet. For generic servlets, you simply override the service() method to provide routines for handling requests. HTTP servlets provide a service method that automatically routes the request to another method in the servlet based on which HTTP transfer method is used, so for HTTP servlets you would override doPost() to process POST requests, doGet() to process GET requests, and so on.

Instantiating and Removing Servlets

Servlets are instantiated by the servlet engine. After the servlet is instantiated, the servlet engine runs its init() method to perform any necessary initializations. Override this method only if you need to perform an initial function for the life of the servlet, such as initializing a counter.

When a servlet is removed from service, the server engine calls the servlet's destroy() method so that the servlet can perform any final tasks and deallocate any resources it may have. Override this method to write log messages or clean up any lingering connections that would not be caught in garbage collection.

How Servlets Handle Requests

When a request is made, NAS hands the incoming data to the servlet engine, which processes the request, including form data, cookies, session information, and URL name-value pairs, into an object of type HttpServletRequest called the request object. Client metadata is encapsulated as an object of type HttpServletResponse and is called the response object. The servlet engine passes both as parameters to the servlet's service() method.

The default service() method in an HTTP servlet routes the request to another method based on the HTTP transfer method (POST, GET, etc.) For example, HTTP POST requests are routed to the doPost() method, HTTP GET requests are routed to the doGet() method, and so on. This enables the servlet to perform different processing on the request data depending on the transfer method. Since the routing takes place in service(), you generally do not override service() in an HTTP servlet. Instead, override doGet() and/or doPost(), etc., depending on the type of request you expect.

Note. The automatic routing in an HTTP servlet is based simply on a call to request.getMethod(), which provides the HTTP transfer method. Since request data is already preprocessed into a name-value list in NAS, you could simply override the service() method in an HTTP servlet without losing any functionality. However, this does make the servlet less portable, since it is now dependent on preprocessed request data.

You must override the service() method (for generic servlets) or the doGet() and/or doPost() methods (for HTTP servlets) to perform the tasks needed to answer the request. Very often, this means accessing EJBs to perform business transactions, collating the needed information (in the request object or in a JDBC ResultSet object), and then passing the newly generated content to a JSP for formatting and delivery back to the client.

How the Servlet Engine Allocates Resources
By default, the servlet engine creates a thread for each new request. This approach is less resource-intensive than instantiating a new copy of the servlet in memory for every request, but you must make sure to avoid threading issues, since each thread operates in the same memory space and variables can overwrite each other.

If a servlet is specifically written as single-threaded, the servlet engine creates a pool of ten (10) instances of the servlet to be used for incoming requests. If a request arrives when all instances are busy, it is queued until an instance becomes available.

For tips on threading issues, see Handling Threading Issues.

Run-Time Servlet Modifications
Servlets and some other application components can be updated at run time without restarting the server. For more information, see Dynamic Reloading.

How Servlets Are Configured Servlet configuration refers to the servlet's metadata, information about the servlet that enables the server to create and use it in the framework of an application. There is currently no standard for servlet configuration.

NAS provides a configuration method whereby an ASCII file stores the metadata needed by the server in a name-type-value (NTV) format. This file is loaded into NAS when the servlet is deployed. The information can also be updated at run-time by the Administration Tool (see the Administration Guide).

Servlets can be configured as part of a specific application, or as generic components used by many applications. NAS considers servlets that are not part of a specific application to be members of the generic application, which means simply that components in the generic application are globally available.

For more information about servlet configuration, see Creating Configuration Files.

Important Servlet Files and Locations Servlet files and other application files reside in a directory structure whose location is known to NAS as AppPath. This variable defines the top of a logical directory tree for the application, similarly to the document path in a web browser. By default, AppPath contains the value BasePath/APPS, where BasePath is the base NAS directory. (BasePath is also a NAS variable.)

AppPath and BasePath are variables held in the NAS registry, a repository for server and application metadata. See The NAS Registry and the Administration Guide.

The following table describes important files and locations for servlets:

Location
Description
BasePath
Top of the NAS tree. All files in this directory are part of NAS. Defined by the NAS registry variable BasePath.
AppPath
Top of the application tree. Files in this directory are part of the generic application. Applications reside in subdirectories of this location. Defined by the NAS registry variable AppPath.
AppPath/ntv
Subdirectory that contains application configuration file and servlet configuration files for the generic application.
AppPath/ntv/appInfo.ntv
Application configuration file for the generic application. Contains pointers to generic-application servlet configuration files in the same directory.
AppPath/ntv/servletInfo.ntv
Servlet configuration file for one or more servlets in the generic application. May be named anything as long as it is referenced in appInfo.ntv in the same directory.
AppPath/appName/*
Top of the subtree for the application appName. Files in this directory are part of the specific application appName. This corresponds to the URL used to access the application's components; see Invoking Servlets.
AppPath/appName/ntv/*
Subdirectory that contains application configuration file and servlet configuration files for the specific application appName.
AppPath/appName/ntv/appInfo.ntv
Application configuration file for the specific application appName. Contains pointers to application-specific servlet configuration files in the same directory.
AppPath/appName/ntv/servletInfo.ntv
Servlet configuration file for one or more servlets in the generic application. May be named anything as long as it is referenced in appInfo.ntv in the same directory.

Deploying Servlets You normally deploy servlets with the rest of an application using the NAS Deployment Manager. You can also choose to deploy servlets manually for the purposes of testing or for updating servlets while the server is running.

For more information, see Deploying and Upgrading Applications.


Designing Servlets
This section describes some of the basic design decisions you have to make when planning the servlets that help make up your application.

Web applications generally follow a request-response paradigm. A user normally interacts with a web application by following a directed sequence of completing and submitting forms. A servlet processes the data provided in each form, performs business logic functions, and sets up the next interaction.

How you design the application as a whole helps to determine how to design each servlet by defining the required input and output parameters for each interaction.

Choose a Component: Servlet or JSP If the layout of a page is its main feature and there is little or no processing involved to generate the page, you may find it easier to use a JSP alone for the interaction.

For example, after the Online Bookstore sample application authenticates a user, it provides a boilerplate "portal" front page where the user can choose one of several tasks, including a book search, purchase selected items, etc. Since this portal conducts little or no processing itself, it could be implemented solely as a JSP.

Think of JSPs and servlets as opposite sides of the same coin. Each can perform all the tasks of the other, but each is designed to excel at one task at the expense of the other. The strength of servlets is in processing and adaptability, and since they are Java files you can take advantage of integrated development environments while you are writing them. However, performing HTML output from them involves many cumbersome println statements. Conversely, JSPs excel at layout tasks because they are simply HTML files and can be edited with HTML editors, though performing computational or processing tasks with them can be awkward. Choose the tool that is right for the job you undertake.

For more information on JSPs, see Presenting Application Pages with JavaServer Pages.

Choose Servlet Type: HttpServlet or GenericServlet Servlets that extend HttpServlet are much more useful in an HTTP environment, since that is what they were designed for. We recommend that all NAS servlets extend from HttpServlet rather than from GenericServlet in order to take advantage of this built-in HTTP support.

For more information, see Types of Servlets.

Create Standard or Non-Standard Servlets One of the most important decisions to make with respect to the servlets in your application is whether to write them strictly according to the official specifications, which maximizes their portability, or whether to utilize the features provided by NAS as APIs. These APIs can greatly increase the usefulness of your servlets in a NAS framework.

You can also create more portable servlets that only take advantage of NAS features if the servlet is running in a NAS environment.

For more information on NAS-specific APIs, see Accessing Optional NAS Features.

Planning for Code Re-Use Servlets by definition are discrete, reusable applications that run on a server. A servlet does not necessarily have to be tied to one individual application. You could create a library of servlets to be used across multiple applications.

However, there are disadvantages to using servlets that are not part of a specific application. In particular, servlets in the generic application are configured separately from those that are part of the application.

For more information, see How Servlets Are Configured.

How Many Servlets for Each Interaction? There are several possibilities for programming a given user interaction with a servlet. The method you choose for a given interaction determines how you write the servlet that handles the interaction.

One servlet handles one request

The most straightforward servlet expects one certain request and provides one certain response, as in the following diagram:

A servlet can tailor the output by setting conditions. For example, a login page could lead to a welcome page for users, an administrative page for site managers, and an error page for incorrect login, as in the following diagram:

One servlet handles multiple requests

You can write a single servlet to handle many similar (or even dissimilar) requests by setting a conditional flag for each request, as in the following diagram:

For example, if a single servlet handles several steps, you could conditionalize the service() method based on a flag in the request object:

flag = request.getParameter("flag");
if ( flag.equals("step1")) {
    process_step1;}
else if ( flag.equals("step2")){
    process_step2;}
}
Additionally, the response the servlet provides can be conditional, based on the input it receives, as in the following diagram:

Several servlets handle one request

If reusable code is your goal, you can create several small servlets to handle individual functions in the course of a request, and each servlet can call other servlets for subprocessing using the forward() method, as in the following diagram:

You can call or include JSPs as well. By this method, you could create a library of discrete functional entities and use them wherever needed.


Creating Servlets
To create a servlet, you must perform the following tasks:

For a description of design considerations, see Designing Servlets. For information about creating the files that make up a servlet, see the following sections:

Writing the Servlet's Class File This section describes how to write a servlet, and the decisions you have to make about your application and your servlet's place in it.

Creating the Class Declaration
To create a servlet, write a public Java class that includes basic I/O support as well as the package javax.servlet. The class must extend either GenericServlet or HttpServlet. Since NAS servlets exist in an HTTP environment, the latter is recommended.

The following example header shows the declaration of an HTTP servlet called myServlet:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class myServlet extends HttpServlet {
    servlet methods...
}
Overriding Methods
Next, you must override one or more methods to provide instructions for the servlet to perform its designated task.

All of the processing done by a servlet on a request-by-request basis happens in the service methods, either service() for generic servlets or one of the doOperation() methods for HTTP servlets. This method accepts the incoming request, processes it according to the instructions you provide, and directs the output appropriately. You can create other methods in a servlet as well.

Business logic may involve authenticating the application's user name and password, accessing a database to perform a transaction, or passing the request to an EJB.

Overriding init

You can override the class initializer init() if you need to initialize or allocate resources for the life of the servlet instance, such as a counter. The init() method runs after the servlet is instantiated but before it accepts any requests. For more information, see the servlet API specification.

Note that all init() methods must call super.init(ServletConfig) in order to set their scope correctly. This makes the servlet's configuration object available to the other methods in the servlet.

The following example init() method initializes a counter by creating a public integer variable called thisMany:

public class myServlet extends HttpServlet {
    int thisMany;
    public void init (ServletConfig config) throws ServletException {
        super.init(config);
        thisMany = 0;
    }
Now other methods in the servlet can access this variable.

Overriding destroy

You can override the class destructor destroy() to write log messages or to release resources that would not be released through garbage collection. The destroy() method runs just before the servlet itself is deallocated from memory. For more information, see the servlet API specification.

For example, the destroy() method could write a log message like this, based on the example for Overriding init above:

out.println("myServlet was accessed " + thisMany " times.\n");
Overriding service, doGet, and doPost

When a request is made, NAS hands the incoming data to the servlet engine, which processes the request, including form data, cookies, session information, and URL name-value pairs, into an object of type HttpServletRequest called the request object. Client metadata is encapsulated as an object of type HttpServletResponse and is called the response object. The servlet engine passes both objects as parameters to the servlet's service() method.

The default service() method in an HTTP servlet routes the request to another method based on the HTTP transfer method (POST, GET, etc.) For example, HTTP POST requests are routed to the doPost() method, HTTP GET requests are routed to the doGet() method, and so on. This enables the servlet to perform different processing on the request data depending on the transfer method. Since the routing takes place in service(), you generally do not override service() in an HTTP servlet. Instead, override doGet() and/or doPost(), etc., depending on the type of request you expect.

Note. The automatic routing in an HTTP servlet is based simply on a call to request.getMethod(), which provides the HTTP transfer method. In NAS, request data is already preprocessed into a name-value list by the time the servlet sees the data, so you could simply override the service() method in an HTTP servlet without losing any functionality. However, this does make the servlet less portable, since it is now dependent on preprocessed request data.

You must override the service() method (for generic servlets) or the doGet() and/or doPost() methods (for HTTP servlets) to perform the tasks needed to answer the request. Very often, this means accessing EJBs to perform business transactions, collating the needed information (in the request object or in a JDBC ResultSet object), and then passing the newly generated content to a JSP for formatting and delivery back to the client.

Most operations that involve forms use either a GET or a POST operation, so for most servlets you override either doGet() or doPost(). Note that you can implement both methods to provide for both types of input, or simply pass the request object to a central processing method, as in the following example:

public void doGet (HttpServletRequest request, 
                   HttpServletResponse response)
            throws ServletException, IOException {
    doPost(request, response);
} 
All of the actual request-by-request traffic in an HTTP servlet is handled in the appropriate doOperation() method, including session management, user authentication, dispatching EJBs and JSPs, and accessing NAS features.

Note. If you have a servlet that you intend to also call using a RequestDispatcher method include() or forward() (see Calling a Servlet Programmatically), be aware that the request information is no longer sent as HTTP POST, GET, etc. RequestDispatcher methods always call service(). In other words, if a servlet overrides doPost(), it may not process anything if another servlet calls it, if the calling servlet happens to have received its data via HTTP GET. For this reason, be sure to implement routines for all possible types of input, as explained above.

Note. Arbitrary binary data, like uploaded files or images, can be problematic, since the web connector translates incoming data into name-value pairs by default. You can program the web connector to properly handle this kind of data and package it correctly in the request object. See Programming the Web Connector for information about handling this type of data in the web connector.

Accessing Parameters and Storing Data
Incoming data is encapsulated in a request object. For HTTP servlets, the request object is of type HttpServletRequest. For generic servlets, the request object is of type ServletRequest. The request object contains all the parameters in a request, and also set your own values in the request. The latter are called attributes.

You can access all the parameters in an incoming request by using the getParameter() method. For example:

String username = request.getParameter("username");
You can also set and retrieve values in a request object using setAttribute() and getAttribute(), respectively. For example:

request.setAttribute("favoriteDwarf", "Dwalin");
This reveals one way to transfer data to a JSP, since JSPs have access to the request object as an implicit bean. For more information, see Using Java Beans.

Handling Sessions and Security
From the perspective of a web server or application server, a web application is a series of unrelated server hits. There is no automatic recognition that a user has visited the site before, even if their last interaction was mere seconds before. A session provides a context between multiple user interactions by "remembering" the application state. Clients identify themselves during each interaction by way of a cookie, or, in the case of a cookie-less browser, by placing the session identifier in the URL.

A session object can store objects, such as tabular data, information about the application's current state, and information about the current user. Objects bound to a session are available to other components that use the same session.

For more information, see Creating and Managing User Sessions.

Upon a successful login, you can direct a servlet to establish the user's identity in a standard object called a session object that holds information about the current session, including the user's login name and whatever other information you want to retain. Application components can then query the session object to obtain authentication for the user.

To provide a secure user session to your application, see Writing Secure Applications.

Accessing Business Logic Components
In the NAS programming model, you implement business logic, including database or directory transactions and complex calculations, in EJBs. A pointer to the request object can be passed as a parameter to an EJB, which then performs the specified task.

You can store the results from database transactions in JDBC ResultSet objects and pass pointers to these objects on to other components for formatting and delivery to the client. You can also store the results in the request object using the method request.setAttribute(), or in the session using the method session.putValue(). Objects stored in the request object are only valid for the length of the request, or in other words for this particular servlet thread. Objects stored in the session persist for the duration of the session, which can span many user interactions.

Note. JDBC ResultSets are not serializable, and thus can not be distributed among multiple servers in a cluster. For this reason, do not store ResultSets in distributed sessions. For more information, see Creating and Managing User Sessions.

This example shows a servlet accessing an EJB called ShoppingCart by creating a handle to the cart by casting the user's session ID as a cart after importing the cart's remote interface. The cart is stored in the user's session.

import cart.ShoppingCart; 
...
// Get the user's session and shopping cart 
   HttpSession session = request.getSession(true); 
   ShoppingCart cart = (ShoppingCart)session.getValue(session.getId());
   // If the user has no cart, create a new one 
   if (cart == null) { 
        cart = new ShoppingCart(); 
        session.putValue(session.getId(), cart); 
   } 
You can access EJBs from servlets by using the Java Naming Directory Interface (JNDI) to establish a handle, or proxy, to the EJB. You can then refer to the EJB as a regular object; any overhead is managed by the bean's container.

This example shows the use of JNDI to look up a proxy for the shopping cart:

String jndiNm = "Bookstore/cart/ShoppingCart"; 
javax.naming.Context initCtx; 
Object home; 
    try { 
          initCtx = new javax.naming.InitialContext(env); 
    } catch (Exception ex) { 
          return null; 
    } 
    try { 
          java.util.Properties props = null; 
          home = initCtx.lookup(jndiNm); 
    } 
    catch(javax.naming.NameNotFoundException e) 
    { 
          return null; 
    } 
    catch(javax.naming.NamingException e) 
    { 
          return null; 
    } 
    try { 
          IShoppingCart cart = ((IShoppingCartHome) home).create(); 
          ... 
} catch (...) {...} 
For more information on EJBs, see Introducing Enterprise JavaBeans.

Handling Threading Issues
By default, servlets are not thread-safe. The methods in a single instance of each servlet can be executed numerous times (up to the limit of available memory) simultaneously, with each execution occurring in a different thread though only one copy of the servlet exists in the servlet engine.

This arrangement is efficient in how it uses system resources, but it can be dangerous because of how memory is managed in Java. Because parameters (objects and variables) are passed by reference, different threads can overwrite the same memory space as a side effect.

To make a servlet (or a block within a servlet) thread-safe, do one of the following:

Delivering Results to the Client
The final activity of a user interaction is to provide a response page to the client. The response page can be delivered to the client in two ways:

Creating a Response Page in a Servlet

You can generate the output page within a servlet by writing to the output stream. The recommended way to do this depends on the type of output.

You must always specify the output MIME type using setContentType() before any other output commences, as in this example:

response.setContentType("text/html");
For textual output, such as plain HTML, create a PrintWriter object and then write to it using println. For example:

PrintWriter output = response.getWriter();
output.println("Hello, World\n");
For binary output, you can write to the output stream directly by creating a ServletOutputStream object and then writing to it using print(). For example:

ServletOutputStream output = response.getOutputStream();
output.print(binary_data); 
Note that your servlet can not call a JSP if you create a PrintWriter or ServletOutputStream object.

Note. If you are using NAS with Netscape Enterprise Server (NES), do not set the date header in the output stream using setDateHeader(). Doing so results in a duplicate date field in the HTTP header of the response page that the server returns to the client. This is because NES automatically provides this header field. Conversely, Microsoft Internet Information Server (IIS) does not add a date header, so you must provide one in your code.

Creating a Response Page in a JSP

Servlets can invoke JSPs in two ways:

Note. You identify which JSP to call by specifying a URI, or Universal Resource Identifier. This is normally a path relative to AppPath, with a leading slash / if the JSP is part of the generic application. For instance, if your JSP is part of an application called OnlineOffice, you would refer to a JSP called ShowSupplies.jsp as OnlineOffice/ShowSupplies.jsp. On the other hand, if ShowSupplies.jsp is part of the generic application and is in a subdirectory, specify the subdirectory with a leading slash, as in /GenericJSPs/ShowSupplies.jsp.

For more information about JSPs, see Presenting Application Pages with JavaServer Pages.

Creating the Servlet's Configuration File Servlet configuration files contain metadata, information about the servlet that identifies it and establishes its role in the application. Some optional NAS features are controlled by configuration entries.

Each servlet requires a configuration file to identify it to NAS. A single configuration file can configure multiple servlets. Additionally, each application must have a configuration file that contains references to all servlet configuration files. A configuration file is a hierarchical list of name-value pairs with ordinal types. The format is called NTV (name-type-value). Each NTV file must contain certain fields in order to properly register the servlet with NAS.

For more information about creating servlet configuration files, see Creating Servlet and Application Configuration Files.

Dynamically Reloading Servlets

You can reload servlets into NAS without restarting the server. Simply overwrite the servlet by redeploying. NAS "notices" the new component and reloads it within 10 seconds. For more information, see Dynamic Reloading.

If you make any post-deployment changes to the ServletRegistryInfo section in a servlet's configuration file, you must stop the server and load the new configuration into the NAS registry in order to make the new configuration visible to NAS. This is because the configuration is read only when servlets are first instantiated.

To load a new servlet configuration file into NAS, perform the following steps to make the changes active:

  1. Stop the server.
  2. Deploy the new configuration file.
  3. Execute servletReg configFile.ntv on the server to register the new configuration file.
  4. Restart the server.
Accessing Optional NAS Features NAS provides many additional features to augment your servlets for use in a NAS environment. These features are not a part of the official specifications, though some are based on emerging Sun standards and will conform to those standards in the future.

For more details on NAS features, see Taking Advantage of NAS Features.

NAS also provides support for more robust sessions, based on a model from a previous version of NAS. This model uses the same API as the session model described in the servlet 2.1 specification, which is also supported. For more details on distributable sessions, see Creating and Managing User Sessions.

Finally, the NAS implementation of security in servlets is a feature, since the servlet 2.1 specification makes no provision for security. The security model described in the forthcoming servlet 2.2 specification mirrors the NAS model for servlets. For more information about security in servlets, see Writing Secure Applications.


Invoking Servlets
You invoke a servlet either by directly addressing it from an application page with a URL, or by calling it programmatically from another servlet that is already running.

Calling a Servlet With a URL Most of the time, you call servlets using URLs embedded as links in your application's pages. This section describes how to invoke servlets using standard URLs.

Invoking Specific Application Servlets
Address servlets that are part of a specific application as follows:

http://server:port/NASApp/appName/servletName?name=value 
Each section of the URL is described in the table below:

URL element
Description
server:port
Address and optional port number for the web server handling the request.
NASApp
Indicates to the web server that this URL is for a NAS application, so the request is routed to the NAS executive server.
appName
The application's name, as configured in appInfo.ntv.
servletName
The servlet's name, as configured in the servlet configuration file.
?name=value...
Optional name-value parameters to the servlet.

The application name appName must correspond to a directory under AppPath (see Important Servlet Files and Locations). In this directory, the servlet engine expects to find a subdirectory ntv, in which there needs to be a file appInfo.ntv, and one or more configuration files defining each servlet used by the application. For example:

http://www.my-company.com/NASApp/OnlineBookings/directedLogin 
Invoking Generic Application Servlets
Address servlets that part of the generic application as follows:

http://server:port/servlet/servletName?name=value 
Each section of the URL is described in the table below:

URL element
Description
server:port
Address and optional port number for the web server handling the request.
servlet
Indicates to the web server that this URL is for a generic servlet object.
servletName
The servlet's name, as configured in the servlet configuration file.
?name=value...
Optional name-value parameters to the servlet.

For example:

http://www.leMort.com/servlet/calcMortgage?rate=8.0&per=360&bal=180000 
Calling a Servlet Programmatically You can call a servlet programmatically from another servlet in two ways, as described below.

Note that you identify which servlet to call by specifying a URI, or Universal Resource Identifier. This is normally a path relative to AppPath. For instance, if your servlet is part of an application called Office, the URL to a servlet called ShowSupplies is shown below. The bold section is the URI:

http://server:port/NASApp/Office/ShowSupplies?name=value 
 

© Copyright 1999 Netscape Communications Corp.