Table of Contents Previous Next PDF

Simple Servlet Example

Simple Servlet Example
This example demonstrates how to use Oracle Jolt to connect to Oracle Tuxedo from a WebLogic servlet. It uses the WebLogic Server to deliver an HTML FORM front end in a standard Web browser.
Text entered by a user into the FORM is sent back to the WebLogic Server via the HTTP POST method that is serviced by a registered WebLogic HTTP Servlet, which calls a Tuxedo service using Oracle Jolt. The text received by the servlet is sent to a Tuxedo service, where it is transposed to uppercase before being returned to the servlet. The form is compiled into a dynamically-generated HTML page by the servlet, then sent back to the Web browser, where the uppercase version of the original text is displayed.
This topic includes the following sections:
Example Components and Prerequisites
There are two parts to the simpapp example for Jolt for WebLogic Server:
The HTTP servlet that is shipped with the examples that are installed in the samples directory where Oracle Tuxedo is installed.
The Tuxedo service application that is shipped with the Tuxedo examples that are installed with Oracle Tuxedo. The Tuxedo simpapp server contains the TOUPPER service, which converts a given string to uppercase.
The source code for the Jolt servlet simpapp example is located in the /samples/jolt/wls/servlet/ directory in the Tuxedo distribution.
The simpapp sample directory contains the following files:
A complete listing of the Tuxedo server-side source code of the simpapp application service is located in $TUXDIR/samples/atmi/simpapp on UNIX systems and in %TUXDIR%\samples\atmi\simpapp on Windows 2003 systems (where TUXDIR is the Tuxedo home directory).
To run this example, you should be familiar with:
Using the Example
The simpapp example is easy to follow. Just launch the simpapp.html page from the WebLogic Server. The simpapp.html page loads an HTML form which contains a text field for entering the string. Type in a string and click the Post button to submit the string as a post request. The SimpAppServlet formats the string you typed for use with the Jolt for WebLogic class libraries, and then dispatches the request to the Tuxedo TOUPPER service, which transposes the string to uppercase and returns it for display in the browser.
Configuring the simpapp servlet example requires the following steps:
Step 1. Perform Preparatory Steps
Set up the Jolt Server. Refer to the Using Oracle Jolt for information about how to configure a Jolt Server.
Use the Jolt Repository BulkLoader file to ensure that the TOUPPER service is defined in the Jolt Repository.
The simpapp example directory has a simpapp.rep file that contains the TOUPPER service definition. Your system administrator should use the Jolt Repository BulkLoader to add this service definition to the existing Jolt Repository on the Tuxedo server. The Jolt Repository BulkLoader package is supplied with the Jolt distribution for Tuxedo. Refer to Using Oracle Jolt for details on how to install this.
On the Tuxedo server, the following code example uses the Jolt BulkLoader to add the TOUPPER service definition:
$ java bea.jolt.admin.jbld //host:port simpapp.rep
where host and port are the hostname and port number of your Jolt Server Listener (JSL), and the simpapp.rep is the BulkLoader file provided by Oracle Jolt, located in one of the following locations:
$TUXDIR/samples/jolt/wls/servlet/ on UNIX
%TUXDIR%\samples\jolt\wls\servlet\ on Windows 2003
Confirm that you have properly set up your CLASSPATH during installation. The WebLogic Server classes library contains the three .jar files that you will need to run this example:
Step 2. Start the WebLogic Server
If you are using a Windows 2003 system, you can start the WebLogic Server from the Start menu. Otherwise, use the startWebLogic script on the command line, in the root directory of the WebLogic Server distribution.
For more information on starting the WebLogic Server, see “Starting and Stopping the WebLogic Server” in the Oracle WebLogic Server Administration Guide.
Step 3. Configure the Servlet in WebLogic Server
Configuration of the Jolt connection pool and startup class MBeans for WebLogic Server 6.0 or later is done through Administration Console.
Copy the simpapp.html page into your WebLogic document root directory.
By default, this is the \config\mydomain\applications\simpapp directory in your WebLogic Server distribution. The HTTP server built into WebLogic looks in this directory for HTML pages and other MIME types.
For the Class Name, enter the following name: bea.jolt.pool.servlet.weblogic.PoolManagerStartUp
There are no arguments for this startup class.
Register the simpapp servlet as a Web application, as follows:
For Step 2, enter the path to the simpapp servlet (or use the Browse feature), and then click the Upload button.
The simpapp servlet is registered as a Web application in WebLogic and appears as an icon under the Deployments\Web Applications folder.
Step 4. Stop and Restart the WebLogic Server
In order to start the Jolt session pool, you must shut down the WebLogic Server, and then restart it. For more information on restarting the WebLogic Server, see “Starting and Stopping the WebLogic Server” in the Oracle WebLogic Server Administration Guide.
Step 5. Compile the Servlet
After restarting the WebLogic Server, compile the SimpAppServlet file, as follows:
Under your WebLogic \config\mydomain\applications\simpapp document root directory, create a new WEB-INF directory.
Copy the web.xml file from the Tuxedo installation directory \samples\jolt\wls\servlet\ into the new WEB-INF directory.
Compile the file, as follows:
javac -d %WL.HOME%\config\mydomain\applications\simpapp\WEB-INF\classes
This step also copies the necessary java classes into a WEB-INF\classes directory.
Step 6. Display the simpapp.html Form
Enter the URL for the simpapp.html file. For example, the default URL is:
where localhost is the host name of the WebLogic Server, and port is the port at which the WebLogic Server is listening for login requests.
A page similar to the one shown in Figure B‑1 is displayed:
Figure B‑1 simpapp.html Example
If you have problems displaying the form, be sure that the simpapp.html file is in the WebLogic document root.
Step 7. Post the FORM Data from the Browser
Enter some text into the text field on the HTML page and submit it by clicking the POST button. Along with the text you entered, other parameters are submitted to the simpapp servlet class running in WebLogic Server.
The following is the relevant section from the simpapp.html file that describes the HTML form:
<form name="simpapp" action="simpapp" method="post">
<input type="hidden" name="SVCNAME" value="TOUPPER">

<table bgcolor=#dddddd border=1>
<td>Type some text here and click the Post button:
<input type="text" name="string">

<td align=center><input type="submit" value="Post!">
This HTML form specifies two input fields: the text you enter and a hidden field. In this example, the value of the hidden field actually specifies the name of the Tuxedo service to be invoked. Although putting the name of the Tuxedo service within the HTML page is flexible and efficient, it is not recommended for production use for security reasons. In this HTML page, you can submit an HTTP request specifying a different service name as the hidden field.
When the WebLogic Server receives the HTTP form request, it invokes the doPost() method of the simpapp servlet and passes the form data into an HttpServletRequest.
Step 8. Process the Request
Before the first request to the simpapp servlet, WebLogic initializes the servlet by calling its init() method. The Jolt session pool is established in the following manner:
ServletSessionPoolManager b_mgr =
Next, the servlet’s doPost() method is executed. This method contains the code to get a connection from the simpapp session pool that was created during the startup of the WebLogic Server. The following code snippet shows the code that is used to retrieve the simpapp session pool.
// Get the "simpapp" session pool
ServletSessionPool session =
(ServletSessionPool) b_mgr.getSessionPool("simpapp");
The Tuxedo service that will be called is identified in a hidden field, which is retrievable from the request object. Retrieve the service name parameter as follows:
String svcnm[] = req.getParameterValues("SVCNAME");
You retrieve the value of the SVCNAME field in a string array that contains a single value; use only the first element of the array. The value set for the SVCNAME hidden field in the form is TOUPPER. This is the name of the Tuxedo service that the servlet invokes, which is passed to the call() method as follows:
// Invoke a service and get the result.
result =[0], req);
The session object in this example is a ServletSessionPool that can accept the HttpServletRequest object directly. Internally, it converts the data into a Jolt DataSet object, which contains the parameters for the TOUPPER service.
The TOUPPER service expects a case-sensitive parameter called "STRING", so it is essential for the text field within the HTML form to be labeled exactly the same, that is, "STRING". Note also that the other data fields, such as the SVCNAME, are not relevant as parameters but don't disrupt the Tuxedo service.
The form parameter is used to actually name the service, which you don't have to pass as a service parameter. It is passed automatically because it is already contained in the HttpServletRequest object.
The TOUPPER service converts the text in the "STRING" parameter to uppercase text and passes it back to the servlet in a ServletResult object that contains the results of an executed call, as well as details about exceptions if any are thrown during the service call.
Step 9. Return the Results to the Client
The final step constructs and sends an HTML page, which contains the results of the service call, back to the client through the HttpResponse output stream. The uppercase result is retrieved from the ServletResult object using the result.getValue() method.
The following is a simple example of passing this data back as HTML that the browser can display:
out.println("<p><center><font size=+1><b>"+
result.getValue("STRING", "")+
The output stream produces a page similar to the one shown in Figure B‑2:
Figure B‑2 Output Stream Results Example

Copyright © 1994, 2017, Oracle and/or its affiliates. All rights reserved.