|
Advertisement |
DIRECT WEB REMOTING - (DWR)
Posted On January 14, 2012 by Geeta Priya filed under Enterprise
DWR is a Java library that enables Java on the server and JavaScript in a browser to interact and call each other as simply as possible.
DWR is one of the AJAX ready-made kits. It was created by Joe Walker in 2005.Although AJAX is popular, but DOM and XMLHttpRequest object details may be a bit strange for Java developers. We are likely to make mistakes in syntax, In DWR, we can hide this problem.
We can get the software, tutorials etc for DWR from
www.directwebremoting.org/dwr/index.htm
dwr.war is placed in the Tomcat5\webapps.
Steps to be followed:
1.As usual we have to write a simple JavaBean.
2.XMLMapping is performed
3.The required dwr jar files and war files can be downloaded from the DWR website.
4.Now,place the war file in Tomcat5\webapps folder.
5.Start the Tomcat server. So, we will get the dwr folder in which the standard structure of the
web application is available. copy and paste the folder in desktop and rename it as mydwr. Now it can be used, by placing it in webapps.
6. mydwr\web-inf\lib folder contains the required jar files as follows:
a) bsf-2.3.jar
b) bsh-2.0b4.jar
c) commons-logging-1.0.4.jar
d) commons-validator-1.1.4.jar
e) dwr.jar
f) jakarta-oro-2.0.8.jar
g) log4j-1.2.12.jar
7.There is no need to make any entry in web.xml file because the directory structure for this
context is readily available.
8.We have to write the dwr.xml file and mapping is performed here.
9.The name of the Javascript must be the same as the name of the JavaBean class.
I have created a folder named as dwrdemo in d: drive.
set path=c:\windows\command;
c:\jdk1.5\bin
Then,i created a java source file named as greeter.java
------------------------------
package mypack;
public class greeter
{
public String greetme(String a)
{
return "how are you?...."+a;
}
}
--------------------------------
Then after compiling ,i placed the class file in D:\tomcat5\webapps\mydwr\WEB-INF\classes\mypack
Next to this,i made an entry in dwr.xml file available in D:\tomcat5\webapps\mydwr\WEB-INF as,follows
----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
"http://getahead.org/dwr/dwr20.dtd">
<dwr>
<allow>
<create creator="new" javascript="greeter">
<param name='class' value="mypack.greeter"/>
</create>
</allow>
</dwr>
----------------------------------------
Thus, the above entry maps the java class 'mypack.greeter' to the javascript
'greeter'. DWR automatically creates the required javascript.
Let us now create greetertest.htm as follows.
----------------------------------------
<html>
<head>
<script type='text/javascript' src='/mydwr/dwr/interface/greeter.js'>
</script>
<script type='text/javascript' src='/mydwr/dwr/engine.js'>
</script>
<script type='text/javascript'
src='/mydwr/dwr/util.js'>
</script>
</head>
<body bgcolor=indigo text=cyan>
<h1>
DEMO FOR DWR
</h1>
<form name='form1'>
<input type='text' name='text1' />
<input type='button'
onclick='job1()' value='greet' />
<script type='text/javascript' language='javascript'>
function job1()
{
s = form1.text1.value;
greeter.greetme(s,reply)
}
reply=function(data)
{
alert(dwr.util.toDescriptiveString(data, 2));
}
</script>
</form>
</body>
</html>
----------------------------------------
Then we have to start the tomcat server.
Go to the browser window and type the url as "http://localhost:8080/dwrdemo/
greetertest.htm"

In the available textbox type any name to get the result as follows: (screen-2).


Author is working at ACCET, Karaikkudi. Tamil Nadu.






Hari Krisna commented, on January 15, 2012 at 8:22 p.m.:
I'm not familiar with programming. givve me some HR related articles.