Files   Prepare   Run   Troubleshooting   Related Topics 

About the Example

This example demonstrates how to use the AbstractAsyncServlet with AJAX by implementing a simple chat application.

The example includes two Servlets: ChatSendServlet that receives the chat message request and ChatReceiveServlet that handles polling message request by the AJAX client.

ChatReceiveServlet decouples the receipt of a servlet request from the sending of its response. If there are no queued messages, ChatReceiveServlet sends the Responses in the future upon the arrival of new messages or timeout. The ChatReceiveServlet does not consume any threads while waiting for the new messages within the timeout period.


Files Used in the Example

Directory Location:

MW_HOME/wlserver_10.3/samples/server/examples/webapp/servlets/async/

(where MW_HOME is the directory containing your Oracle WebLogic Server installation)

File

Click source files to view code.

Description

application.xml Java EE standard enterprise application deployment descriptor.
build.xml Ant build file that contains targets for building and running the example.
ExamplesFooter.jsp Java Server Page containing the Example Footer.
ExamplesHeader.jsp Java Server Page containing the Example Header.
main.jsp Main Java Server Page of the chatting program.
chat.js JavaScript file that sends chat messages to and polls messages from the Chat Server.
ChatSendServlet.java Servlet that processes the message sent by the AJAX Client .
ChatReceiveServlet.java Implementation of AbstractAsyncServlet.
ChatSession.java Simple class responsible for maintaining the users and messages .
web.xml Standard Web application deployment descriptor.

Prepare the Example

Prerequisites

Before working with this example:

  1. Install Oracle WebLogic Server, including the examples.
  2. Start the Examples server.
  3. Set up your environment.

Configure Oracle WebLogic Server

  No special configuration is required for this example

Build and Deploy the Example

To build the example, follow these steps:

  1. Change to the SAMPLES_HOME\server\examples\src\examples\webapp\servlets\async directory, where SAMPLES_HOME refers to the main Oracle WebLogic Server examples directory, such as d:\Oracle\Middleware\wlserver_10.3\samples.
  2. Execute the following command:

    ant build

    This command compiles and stages the example.
  3. Execute the following command:

    ant deploy

    This command deploys the example on the wl_server domain of your Oracle WebLogic Server installation.


Run the Example

To run the example, follow these steps:

  1. Complete the steps in the "Prepare the Example" section.
  2. In your development shell, run the example by executing the following command from the example directory (SAMPLES_HOME\server\examples\src\examples\webapp\servlets\async):

    prompt> ant run

    This command executes the build.xml run target, which opens your default browser to the following URL:
    http://localhost:port/asyncServlet/main.jsp

    Where:

Enter a chat handle in the browser to enter the chat room. Then, in a new browser window, invoke the chat servlet using the URL above and enter a different chat handle so you can chat with the first handle.


Troubleshooting


Related Topics

(Internet connection required.)


Copyright © 1996, 2009, Oracle and/or its affiliates. All Rights Reserved.