Itegrating DWR (Direct Web Remoting) with Spring

Hi Springers, I have used DWR (Direct Web Remoting) in my last project which was pretty interesting and I want to share the simplest way of using DWR with spring application. Download the latest version of dwr.jar from here. And put it in the /WEB-INF/lib folder. I have used DWR 2.0.5.

Add the following lines in your web.xml

<pre><servlet>
  <servlet-name>dwr-invoker</servlet-name>
  <display-name>DWR Servlet</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></pre>

Now create a dwr.xml in the WEB-INF folder alongside web.xml and add the following line in that file.

<pre><!DOCTYPE dwr PUBLIC
    "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
    "<a href="http://getahead.org/dwr/dwr20.dtd">http://getahead.org/dwr/dwr20.dtd</a>">

<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></pre>

To check go to the following URL.

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

You should see a page showing you the classes that you’ve selected.

To learn detail about DWR please visit the documentation site of DWR.

Read More