DWR is Easy Ajax for Java

Home arrow AJAX Tutorials arrow Tutorial arrow DWR is Easy Ajax for Java
DWR is Easy Ajax for Java Print E-mail
Contributed by Howell   
Friday, 15 September 2006

What is DWR?

Direct Web Remoting (DWR) is designed to be used with Java, one of the most widely used object-oriented languages. Java is not limited to any particular platform, but its main use has been server-side rather than desktop applications.

DWR consists of two main parts:
  • A Java Servlet running on the server that processes requests and sends responses back to the browser.
  • JavaScript running in the browser that sends requests and can dynamically update the webpage.

How It Works  (DWR is Easy Ajax for Java)

DWR works by dynamically generating Javascript based on Java classes. The code does some Ajax magic to make it feel like the execution is happening on the browser, but in reality the server is executing the code and DWR is marshalling the data back and forwards.

Installing DWR

Although the actual installation of DWR is straightforward, there are a number of prerequisites that need to be taken care of first.

Edit the config files

 The following lines need to be added to WEB-INF/web.xml. The <servlet> section needs to go with the other <servlet> sections, and likewise with the <servlet-mapping> section.

<servlet>
  <servlet-name>dwr-invoker</servlet-name>
  <display-name>DWR Servlet</display-name>
  <servlet-class>uk.ltd.getahead.dwr.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>


Then create a dwr.xml file that lives in WEB-INF alongside web.xml. A simple way to start is with something like this:

<!DOCTYPE dwr PUBLIC
    "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
    "
http://www.getahead.ltd.uk/dwr/dwr10.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>

Last Updated ( Friday, 15 September 2006 )

  home              contact us

 

©2006-2010 DeveloperZone.biz   All rights reserved     powered by Mambo Designed by Siteground