DWR (Direct Web Remoting) is a Web remote call framework. Leveraging this framework makes it easy to develop Ajax. Using DWR, you can invoke the service directly from the client using JavaScript -side Java method and returns a value to JavaScript as if it were a direct local client invocation (DWR dynamically generates JAVASCRIP code based on Java classes). Its latest version DWR0.6 add many features such as: Support for DOM trees automatic configuration, support spring (JavaScript remote invoke Spring bean), better browser support, and an optional commons-logging journaling operation.
Dwr:easy AJAX for JAVA
DWR is a Java Open Source library that helps you implement AJAX Web sites.
It allows you to invoke JavaScript code in the browser to call Java on the Web server, just as in Java code in the browser.
Dwr mainly consists of two parts:
- A servlet running on the server handles the request and returns the result to the browser.
- JavaScript, which runs on the browser, can send requests and dynamically change the page.
DWR will generate JavaScript code dynamically based on your Java class. The magic of this code is to make you feel that the entire Ajax call takes place on the browser, but the fact is that the server executes the code and DWR is responsible for the transfer and transformation of the data.
This remote invocation between Java and JavaScript makes the DWR user feel like the RMI or SOAP RPC mechanism used to be used. And this process does not require additional browser plug-ins.
Java is synchronized, while Ajax is asynchronous. So when you call a remote method, you give Dwr a callback function that DWR call when the data comes back from the network.
This diagram shows how DWR changes the contents of the Drop-down list in the onclick event.
DWR dynamically generates a corresponding client Ajaxservice class (Javascript) for the server-side Ajaxservice class (Java). This class is called by EventHandler. DWR handles the details of the entire remote call, including converting parameters and return values between JavaScript and Java. And then in this example, it executes the callback function you provided (populatelist), which then uses the tool function provided by DWR to change the content of the page.
DWR helps you produce a very interactive web site that provides some JavaScript libraries to help you deal with DHTML and provides examples for reference.
To see how to start using DWR you can look at the start guide and download Dwr
Don't like this way, the client should not call the server-side method directly, so the coupling between client and server increases </