JavaScript EditorFreeware JavaScript Editor     Ajax Tutorials 

Main Page

Previous Page
Next Page


Direct Web Remoting (DWR) is designed to be used with Java, one of the most widely used object-oriented languages. Java is not limited to any particular platform, but its main use has been server-side rather than desktop applications.


Remember that the similarity in names between Java and JavaScript owes more to marketing methods than inherent relationships between the two languages. Although the syntax of both is identical in a lot of places, there are many differences, especially when it comes to data typing.

How It Works

DWR also uses reflection to examine any of the classes specified in its configuration files. It then dispatches JavaScript to the client in which each function resembles those on the class but has an extra parameter specifying a function to call when the data is returned. As with JPSpan, DWR uses a cross-browser library and the relevant version of XmlHttpRequest, the ActiveX version if running Internet Explorer or the native JavaScript version for the Mozilla-based browsers and others such as Safari and Konqueror.

Installing DWR

Although the actual installation of DWR is straightforward, there are a number of prerequisites that need to be taken care of first.

Installing the Java SDK

First, download the Java software development kit from The following examples are based on the version 1.5 kit, so if you have an earlier version you will need to upgrade.


You have a number of options available at Sun's site that can be confusing at times. For development work, you basically have two choices: either the plain development kit (which will also install the runtime files necessary for all Java applications) or the one that includes the NetBeans IDE (Integrated Development Environment). All the examples in this chapter can be developed and run without the IDE. This can then be downloaded separately if you are moving on to more serious Java development.

You can then install the kit and the runtime and create or update any environment variables as detailed in the accompanying readme file.

Installing the Web Server

Next, you will need a web server that supports Java servlets and JSP. The most common one is Tomcat, part of the Apache Jakarta project. There are versions available for Windows and UNIX/Linux, and details of how to install and configure them can be found at


At the URL just given you will see that there is a ready-to-run version that has been pre-configured with a number of standard settings. That is the version that was used for this chapter's examples; other than modifying the server's port so that it didn't clash with IIS, it worked out of the box.

After the Java SDK and the Tomcat server are installed, you should be able to start up Tomcat as shown in the tutorial and navigate to the home page. This will give you access to the management pages as well as a number of test pages and samples that you can use to make sure everything is set up correctly.

Finally, obtain the DWR files from This is only a small download of about 150KB. The main file, dwr.jar, needs to be placed in a specific folder of your web application. Put these files aside until the basic folder structure has been created.

Setting Up a Test Site

To set up a test site for DWR, create the folder structure, headed by DwrTest, as shown in Figure 10-5.

Image from book
Figure 10-5

The next step is to create two XML configuration files: web.xml and dwr.xml. First, the basic structure of web.xml:

<web-app xmlns=""

    <display-name>DWR Servlet</display-name>


Previous Page
Next Page

JavaScript EditorAjax Editor     Ajax Validator