Recipe 20.4 Configuring Flash Remoting for J2EE

20.4.1 Problem

You want to configure Flash Remoting for J2EE.

20.4.2 Solution

Copy the flashgateway.jar file into the web application's WEB-INF/lib directory and configure a servlet and servlet-mapping in the web.xml file. If you use JRun 4 as your J2EE server, Flash Remoting comes preinstalled.

20.4.3 Discussion

If you are using JRun 4 as your J2EE server, Flash Remoting comes preinstalled and you do not need to purchase or configure any additional software. If you use a third-party J2EE server, such as IBM WebSphere or BEA Weblogic, the Flash Remoting for J2EE gateway, sold separately by Macromedia, allows Flash clients to communicate with Enterprise Java applications (see If you are not using JRun 4, you must download and install either the trial version or full version before proceeding. (As an open source alternative, see the OpenAMF project at

All the necessary code for Flash Remoting for J2EE is contained within the flashgateway.jar file. You can find this file in the Flash Remoting installation (on Windows machines this is typically under C:\Program Files\Macromedia\Flash Remoting MX). You can either extract the .jar file from the .war file (flashgateway-samples.war) or copy it from the sample application (within the sample\WEB-INF\lib subdirectory). You should copy this .jar file to the WEB-INF/lib directory of your own J2EE web application.

Once you have copied the .jar file into your web application, you only need to configure a servlet and servlet-mapping for the J2EE Flash Remoting gateway servlet that is contained within the .jar file. You should map the servlet to the URL pattern /gateway (the name /gateway is not required, but it is a logical choice). The following shows an example web.xml file with the necessary <servlet> and <servlet-mapping> tags:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
  <display-name>My Application</display-name>

The correct gateway URL to use within your Flash movies to connect to Flash Remoting for J2EE (as discussed in Recipe 20.1) should be of the form:


in which j2eeServerNameOrIP is the domain name or IP address of the J2EE application server, and applicationContext is the context for the web application as it is configured by the application server. For example, the correct gateway URL for web application on localhost (port 80) with a context of /myApplication is:


20.4.4 See Also

Recipe 20.1, Recipe 20.13, Recipe 20.17, and Recipe 20.20. "Flash Remoting for J2EE Developers" at and The OpenAMF Java Flash Remoting project (, a free, open source alternative to Macromedia's Flash Remoting for J2EE. Information on JRun can be found at

    Part I: Local Recipes
    Part II: Remote Recipes