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.

Kevin began developing for the Web in 1995 and is a highly respected technical author. Kev is a world-renowned author, speaker and JavaScript expert. He has a passion for making web technology easy to understand by anyone. Yes, even you!

Get your free chapter of Level Up Your Web Apps with Go

Get a free chapter of Level Up Your Web Apps with Go, plus updates and exclusive offers from SitePoint.

  • Octal

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

  • lemkepf

    Anyone know of a library for PHP or ASP?

  • mrsmiley

    JPSpan should handle the Javascript to PHP requests lemkepf

  • 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 is a similar lib for .net

Related books & courses
Available now on SitePoint Premium

Preview for $1