This document provides an overview of Direct Web Remoting (DWR), including:
1) DWR allows Java code to be executed from JavaScript and JavaScript code to be executed from Java, enabling bidirectional communication between the two languages.
2) A tutorial is given demonstrating how to build a simple calculator application using DWR with steps to set up the project, write the business logic, and create the front-end.
3) Advantages of DWR are that it allows Java functions to be called from JavaScript like RMI or SOAP, automatically generates Java versions of JS functions, and exposes business methods through JavaScript.
19. Write your Business Logic package org.hussulinux.samples; public class Calculator { public Calculator() { } public int add( int a, int b) { return a + b; } public int subtract( int a, int b) { return a - b; } public int multiply( int a, int b) { return a * b; } public float divide( int a, int b) { if (b == 0) { return 0; } else return ( float )(( float )a / ( float )b); } }
20. Add dwr.xml along with web.xml <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd"> <dwr> <allow> <create creator="new" javascript="Calculator"> <param name="class" value="org.hussulinux.samples.Calculator"/> </create> </allow> </dwr>