Using a Java servlet to generate XML

Servlets are Java programs that run in response to a request from a Web browser. Unlike agents, servlets load when the Web server starts up and stay resident on a server. They are commonly used for generating and updating Web pages dynamically and for exchanging data between different applications. You can extend the power of servlets to bridge applications by using XML as a common language between applications. Not only can a Java servlet produce and deliver XML tags to the server for processing, a servlet can also interact with the LotusXSL processor to format the data described by the XML tags. XML in conjunction with XSL provides you with a powerful tool for customizing the transfer of data.

Examples of XML servlet applications

As an example of how a servlet can leverage XML to deliver a customized package of data, consider an organization where field sales representatives download information from an Domino® database using a variety of devices, such as an Notes® client, a browser, or a PDA. A sales representative can request all of the information pertaining to a particular client from the Domino® application. A servlet assembles the information from a variety of data sources, and packages the data with the appropriate XML tags. The servlet can also use the LotusXSL processor to apply styles to the XML-tagged data and deliver the data in the format best suited to the connecting device. In this scenario, the sales representative connecting with a PDA on a low-bandwidth phone line will get less information than the sales representative connecting with a Notes® client running on a high-bandwidth network connection.

The following graphic shows the relationship between the connecting devices, the Domino® application running the servlet, and the back-end databases:

Image of XML agent

In another example of how a servlet can supply meaningful, customized data, consider a real estate application with data on houses for sale stored in a Domino® database. A real estate agent or a potential buyer uses a Web browser to request information about property for sale from the Domino® application. The user specifies search criteria, such as the desired number of bedrooms. A servlet runs in the Domino® application, finding and assembling all of the documents that match the specified criteria. The servlet dynamically wraps the data it finds in the correct XML tags -- such as <HOUSE> and <HOUSETYPE>. It then uses the LotusXSL processor to apply styles from an XSL stylesheet and transforms the XML-tagged data to HTML, pushing the correctly formatted data to the requesting browser.

Creating and using a servlet

You can either create a servlet from scratch, refer to an existing servlet by its URL, or use a pre-built servlet. Each time you modify a servlet, you must restart the server to see the changes. Running a servlet involves writing the servlet, enabling servlet support in Domino®, and, if necessary, setting servlet properties.

For complete instructions on running a servlet on a Domino® server, see "Overview of Java Servlets."

For general information on Java servlets, visit the Oracle site at http://www.oracle.com/technetwork/java/index.html.

Including XML in a servlet

To include XML tags in a Java servlet, you need the LotusXSL Processor. You can download the LotusXSL Processor from the IBM® AlphaWorks site, at http://alphaworks.ibm.com/formula/LotusXSL