dwr框架使用总结——简单示例
1、新建web项目,项目名为dwr
2、导入以下jar包:
dwr.jar、classes12.jar、commons-logging-1.0.4.jar和commons-logging.jar
3、在WEB-INF下面新增dwr.xml
xml中的内容如下:
<?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=”firstDwr” scope=”session”>
<param name=”class” value=”com.shijiaoyun.dwr.test.DwrTest” />
<include method=”showMessage” />
</create>
</allow>
</dwr>
注:
javascript=”firstDwr” 表示页面中引用时的名称
value=”com.shijiaoyun.dwr.test.DwrTest” 表示将要调用的类
<include method=”showMessage” /> 表示将要调用的类中的方法名
4、在web.xml中添加一下内容:
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<display-name>DWR Servlet</display-name>
<servlet-class>uk.ltd.getahead.dwr.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>
5、页面中引入dwr:
<script type=”text/javascript” src=”/dwr/dwr/engine.js”></script>
<script type=”text/javascript” src=”/dwr/dwr/util.js”></script>
<script type=”text/javascript” src=”/dwr/dwr/interface/firstDwr.js”></script>