From: http://directwebremoting.org/dwr/introduction/getting-started.html
Getting started with DWR
There are several ways to get started withdwr. We recommend the following:
Follow the 5 steps outlined below.
Download the DWR. War file and experimentwith the examples.
Once DWR is up and running learn how towrite JavaScript For DWR.
DWR in 5 steps
1. Install the dwr jar File
Download the DWR. jar file. Place it hosts the WEB-INF/lib directory of your web application.
2. Install the commons logging JAR File
DWR depends on commons logging. Downloadthe commons-logging.jar and place it into the WEB-INF/lib directory of your webapplication.
3. Add the DWR servlet definition andmapping to your application's web. xml
Add the following lines to your webapplication's deployment descriptor (WEB-INF/web. XML ). the <servlet> section needs to go with any existing <servlet> sections, and likewisewith the <servlet-mapping> section.
<Servlet>
<Display-Name> DWR servlet </display-Name>
<Servlet-Name> DWR-invoker </servlet-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>
4. Create the DWR configuration file (DWR. XML)
Create a new file in you web application 'sweb-INF directory (alongside web. XML) named DWR. xml.
A simple way to start is with somethinglike this:
<! Doctype DWR public
"-// Getahead limited // DTD direct Web remoting 3.0 // en"
Http://getahead.org/dwr/dwr30.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>
The DWR config file defines what classesdwr can create and remote for use by JavaScript. In the example abve we aredefining 2 classes that are Remoted and giving the classes names in JavaScript.
The new creator that we used above uses thepublic no-ARGs constructor that all Java Beans must have. It is also worthremembering that DWR has one restriction:
Avoid reserved JavaScript words; methodsnamed after reserved words are automatically excluded. most JavaScript reservedwords are also Java reserved words, so you won't be having a method called "Try ()" anyway. however the most common Gotcha is "Delete ()",
Which has special meaning in Javascript but not Java.
Visit the DWR. xml documentation for adetailed description of the DWR. xml file, creators and converters.
5. Take DWR for a test drive!
Go to the following URL:
Http: // localhost: 8080/[YOUR-WEBAPP-CONTEXT]/DWR/
You shoshould see a page showing you theclasses you configured in step 4. having followed a link you shoshould see anindex of all the methods ready for calling-simply enter the requiredparameters (if parameters are required) and click the execute button. thesepages
Are valuable debugging tools and dynamically generated by DWR when thedebug init-Param is set to true.
How to make use of this from your webapplication
We have a whole section on writingjavascript with DWR, and there are a number of examples in the sidebar thatdemonstrate how to dynamically alter the text in Web pages, update lists, manipulate forms and perform live table editing. each has a description
Of howit works.
Another way to get started is to look at the source from the pages that you just viewed:
Go tohttp: // localhost: 8080/[YOUR-WEBAPP-CONTEXT]/DWR/and click on your class
View Source and find the line that executesthe method that you are interested in.
Paste the text into an HTML or JSP page inyour web-app.
Include links to the DWR JavaScript filesthat make the magic happen:
<Scriptsrc = '/[YOUR-WEBAPP-CONTEXT]/DWR/interface/[Your-script]. js'> </SCRIPT>
<Scriptsrc = '/[YOUR-WEBAPP-CONTEXT]/DWR/engine. js'> </SCRIPT>
You can omit the/[YOUR-WEBAPP-CONTEXT]/section and use relative paths in your web pages if you wish.
Next step: Learn about writing javascriptthat interacts with DWR.
What if it doesn' t work?
We have a page containing troubleshootingadvice and common problems and their fixes. This is the first place to look.