DWR is AJAX for Java

Share this article

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 YankKevin Yank
View Author

Kevin Yank is an accomplished web developer, speaker, trainer and author of Build Your Own Database Driven Website Using PHP & MySQL and Co-Author of Simply JavaScript and Everything You Know About CSS is Wrong! Kevin loves to share his wealth of knowledge and it didn't stop at books, he's also the course instructor to 3 online courses in web development. Currently Kevin is the Director of Front End Engineering at Culture Amp.

Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week