DWR (Direct Web Remoting) is a java library set that allows easy server client communication. It is an open source licensed under Apache Software. The latest version released is DWR 2.0.DWR works simply by evoking Java function on the server side by the JavaScript on the client side as in Ajax and JavaScript from client side by java functions on the server side also known as reverse Ajax. DWR has prominent features like reverse Ajax, call batching and marshalling of almost all data structure between java(server side) and JavaScript(client side).Also it easily integrates with Ext, Dojo, Jquery, YUI, Spring, Guice etc.
PRINCIPLE
DWR makes Remote Procedure Calls from client to server and back via usage of java script-java functions in its library set. It generates a proxy client side stub in java script code and a server side servlet which handles the dispatching and marshalling of data (parameters and return values).
The most prominent feature of DWR is “Reverse Ajax”. It provides with ability to send data from server to client asynchronously. Usually it is not possible for a server to communicate with client directly. This barrier has overcome through three methods provided by DWR namely Polling, Comet, and Piggyback
Polling
In this method browser sends request to server regularly in a frequent interval
of time to get latest updates from the server. It is quite simple to implement but
it can easily overload the server.
Comet
Comet allows server to process the request from the client side slowly and give response slowly as scheduled. The advantages of this method are low-latency in data transfer, goes easy on server and no need to wait for next client request.
Piggyback:
In Piggyback the server waits for the request from the browser to send its update
CONFIGURE DWR 2.0 WITH APPLICATION
1. Download dwr.jar from the official web site of DWR and place it in WEB-INF/lib of web application DWR 2.0 also requires commons-logging jar file.
2. Add the given below code WEB-INF/web.xml
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<display-name>DWR </display-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
3. Create dwr.xml file in WEB-INF
<!DOCTYPE dwr PUBLIC
“-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN”
“http://getahead.org/dwr/dwr20.dtd”>
<dwr>
<allow>
<create creator=”new” javascript=”JDate”>
<param name=”class” value=”java.util.Date”/>
</create>
<create creator=”new” javascript=”Demo”>
<param name=”class” value=”your.java.Bean”/>
</create>
</allow>
</dwr>
4. Go to following url
“http://localhost:8080/[YOUR-WEBAPP]/dwr/“
You can see the classes you have written in the dwr.xml. Following the link you will see an index of methods.
Of course DWR provides you easy way for server-client communication and allows using RMI like syntax in the client side javascript. It also has some disadvantages such as backend methods are exposed to client side and custom converter (marshaller, unmarshaller) should be created for Java objects. Inspite of all this cons and restrictions posed by DWR, it proved a handy api for web developers.

DWR (Direct Web Remoting) is a java library set that allows easy server client communication. It is an open source licensed under Apache Software. The latest version released is DWR 2.0.DWR works simply by evoking Java function on the server side by the JavaScript on the client side as in Ajax and JavaScript from client side by java functions on the server side also known as reverse Ajax. DWR has prominent features like reverse Ajax, call batching and marshalling of almost all data structure between java(server side) and JavaScript(client side).Also it easily integrates with Ext, Dojo, Jquery, YUI, Spring, Guice etc.

PRINCIPLE

DWR makes Remote Procedure Calls from client to server and back via usage of java script-java functions in its library set. It generates a proxy client side stub in java script code and a server side servlet which handles the dispatching and marshalling of data (parameters and return values).

The most prominent feature of DWR is “Reverse Ajax”. It provides with ability to send data from server to client asynchronously. Usually it is not possible for a server to communicate with client directly. This barrier has overcome through three methods provided by DWR namely Polling, Comet, and Piggyback

Polling

In this method browser sends request to server regularly in a frequent interval of time to get latest updates from the server. It is quite simple to implement but  it can easily overload the server.

Comet

Comet allows server to process the request from the client side slowly and give response slowly as scheduled. The advantages of this method are low-latency in data transfer, goes easy on server and no need to wait for next client request.

Piggyback:

In Piggyback the server waits for the request from the browser to send its update

CONFIGURE DWR 2.0 ON APPLICATION

1. Download dwr.jar from the official web site of DWR and place it in WEB-INF/lib of web application DWR 2.0 also requires commons-logging jar file.

2. Add the given below code WEB-INF/web.xml

<servlet>

<servlet-name>dwr-invoker</servlet-name>

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

<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>

<init-param>

<param-name>debug</param-name>

<param-value>true</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>dwr-invoker</servlet-name>

<url-pattern>/dwr/*</url-pattern>

</servlet-mapping>

3. Create dwr.xml file in WEB-INF

<!DOCTYPE dwr PUBLIC

“-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN”

“http://getahead.org/dwr/dwr20.dtd”>

<dwr>

<allow>

<create creator=”new” javascript=”JDate”>

<param name=”class” value=”java.util.Date”/>

</create>

<create creator=”new” javascript=”Demo”>

<param name=”class” value=”your.java.Bean”/>

</create>

</allow>

</dwr>

4. Go to following url

“http://localhost:8080/[YOUR-WEBAPP]/dwr/“

You can see the classes you have written in the dwr.xml. Following the link you will see an index of methods.

Of course DWR provides you easy way for server-client communication and allows using RMI like syntax in the client side javascript. It also has some disadvantages such as backend methods are exposed to client side and custom converter (mashaller, unmarshaller) should be created for Java objects. Inspite of all this cons and restrictions posed by DWR, it proved a handy api for web developers.