1
dwr.jar lib
commons-logging-1.1.1.jar
web.xml
sevlet dwr-invoker path
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<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>
</web-app>
------------------------------------------------------------------------------
2 js
create xml file from a DTD file-->http://getahead.org/dwr/dwr30.dtd
dwr.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN"
"http://getahead.org/dwr/dwr30.dtd">
<dwr>
<allow>
<create creator="new" javascript="HelloWorldService">
<param name="class" value="com.test.HelloWorldService"></param>
</create>
</allow>
</dwr>
------------------------------------------------------------------------------
3
js
jquery1.4.js
jsp js
<script src="./dwr/interface/LogService.js"></script>//<-- js
<script src="./dwr/engine.js"></script>
<script type="text/javascript" src="./js/jquery-1.4.js"></script>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script src="./dwr/interface/HelloWorldService.js"></script>
<script src="./dwr/engine.js"></script>
<script type="text/javascript" src="./js/jquery-1.4.js"></script>
<script>
function alertMsg(data) {
$("div#area").html(data);
}
$("document").ready(
function() {
$("input#pressIt").click(
function() {
HelloWorldService.sayHello('this is letter!', alertMsg);
}
)
}
)
</script>
</head>
<body>
<div id="area" style="clear: left;"></div>
<input style="float: left;" id="pressIt" type="button"
value="HelloWorldService" />
</body>
</html>
------------------------------------------------------------------------------
4
HelloWorldService.java
package com.test;
public class HelloWorldService {
public String sayHello(String message){
return message;
}
}