1.项目目录\WebRoot\WEB-INF\lib下方dwr.jar
2.项目目录\WebRoot\WEB-INF下建立dwr.xml
dwr.xml内容:
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://www.getahead.ltd.uk/dwr//dwr20.dtd">
<dwr>
<allow>
<create creator="new" javascript="TestDwr">
<param name="class" value="dwr.TestDwr"/>
</create>
</allow>
</dwr>
3.web.xml里配置
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>logLevel</param-name>
<param-value>WARN</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
4.建立一个TestDwr.java
TestDwr.java内容
package dwr;
public class TestDwr {
public String getStr(String str)
{
return str;
}
}
5.建立一个testDwr.jsp
testDwr.jsp内容
<script src='/dwr/interface/TestDwr.js'> </script>
<script src='/dwr/engine.js'> </script>
<script src='/dwr/util.js'> </script>
<script type="text/javascript">
function getDwr(){
TestDwr.getStr("helloDwr!",alertStr);
}
function alertStr(str){
alert(str);
}
</script>
<input type="button" onclick="getDwr()" value="测试dwr"/>
黑色头发:http://heisetoufa.iteye.com