DWR is AJAX for Java

Tweet

Java and JavaScript. Such similar names, but the technologies they refer to are worlds apart… or at least they were until now.

The technique of remote scripting enables JavaScript code running in a Web browser to do things on the Web server and display the results without loading a new Web page. When the results sent by the Web server are in XML format, the technique is called AJAX.

The newly-released Direct Web Remoting (DWR) library greatly simplifies AJAX with Java Web applications.

The library takes all the drudgery out of remote scripting with a Java Web application, but it does require that you know what you’re doing. Beginners in either JavaScript or Java are likely to have a tough time.

You must add a JAR file to your Web application on the server, set up a special servlet to handle the script requests, and then configure one or more classes that you wish to make available from JavaScript. The configuration is done with a nice, clean XML file, where you can specify how each class is instantiated (per request, per session, etc.).

On the client side, you have to include the general DWR JavaScript library as well as the JavaScript code generated for your particular configuration.

While the setup can seem a bit twisty at first, it’s well worth the effort. Your JavaScript code can then transparently call server-side functions without regard for data types or event handling… it all just works.

For advanced developers, DWR does a great job of integrating with Web application frameworks, is fully extensible with pluggable data types and object instantiation methods, and even comes with built-in support for the Spring framework.

While DWR is certainly the newest, I’m sure it’s not the only library for remote scripting with Java Web applications. Have you used another? If so, I’d like to hear about your experiences with it.

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • http://boyohazard.net Octal

    Thanks for the link. Something I have been meaning to look into (remote scripting with Java)

  • http://www.paulandmichelle.net lemkepf

    Anyone know of a library for PHP or ASP?

  • http://www.realityedge.com.au mrsmiley

    JPSpan should handle the Javascript to PHP requests lemkepf

  • http://www.saumendra.com saumendra

    The future of DWR(Dynamic web Remoting) could be mearged with .NET technologies. As .NET have the feature of compiling a request for further use, added with a feature like DWR and AJAX it will boost the server-client architecture.

  • laurent

    ajax.net is a similar lib for .net