DWR is tool for enabling RMI on web-server from JavaScript at the client.
What need you do to create first DWR application.
1) Download DWR library.
2) Add description to web.xml
<servlet>
3) Create a class for remote invocation. Let it be following...
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
package my;
4) Create dwr.xml description at WEB-INF.
import ...
public class Server {
private int count = 0;
public int getCount() {return count;}
public void increase() {count++}
}
<!DOCTYPE dwr PUBLIC
This means, if your-web-app/dwr/client.js is requested, DWR will create an instance of my.Server class and a JavaScript stub for it. You may see how this stub looks by link your-wed-app/dwr/interface/server
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
<create creator="new" javascript="server">
<param name="class" value="my.Server"/>
</create>
</allow>
</dwr>
// Provide a default path to dwr.engine
5) Create page using Server invocaion.
if (dwr == null) var dwr = {};
if (dwr.engine == null) dwr.engine = {};
if (DWREngine == null) var DWREngine = dwr.engine;
if (server == null) var server = {};
server._path = '/jmxWebApp/dwr';
server.getCount = function(callback) {
dwr.engine._execute(client._path, 'client', 'invoke', callback);
}
server.increase = function(callback) {
dwr.engine._execute(client._path, 'client', 'setAttribute', callback);
}
<html>
<head>
<title>DWR_JMX test</title>
<script type="text/javascript" src='dwr/engine.js'></script>
<script type="text/javascript" src='dwr/util.js'></script>
<script type="text/javascript" src='dwr/server.js'></script>
</head>
<body>
<script type="text/javascript">
server.getCount(new Function("data", "alert(data);"));
server.increase(new Function(alert("Value increased"));
server.getCount(new Function("data", "alert(data);"));
</script>
</body>
</html>
Wednesday, August 1, 2007
"Hello, world!" with DWR tool
Автор Frog007 на 7:23 AM
Ярлыки: DWR, java, JavaScript
Subscribe to:
Post Comments (Atom)
2 comments:
What sould we expect when the program runs?
Hello, How do I get in touch with you? There is no email or contact info listed .. please advise .. thanks .. Mary. Please contact me maryregency at gmail dot com
Post a Comment