DWR 入门

引入DWR框架的步骤
1.添加 dwr.jar 包 在 http://getahead.ltd.uk/dwr/ 下载 dwr.jar,放到WEB-INF/lib下
2.编写 dwr.xml,修改 web.xml

dwr.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
    "http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
 <allow>
  <create creator="new" javascript="HelloJS1">
   <param name="class" value="wust.Hello"></param>
  </create>
 </allow>
</dwr>

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>true</param-value>
 </init-param>
 </servlet>
 <servlet-mapping>
 <servlet-name>dwr-invoker</servlet-name>
 <url-pattern>/dwr/*</url-pattern>
 </servlet-mapping>
3.编写 jsp 页面, js文件,java 源文件。

test.jsp
<%@ page language="java" pageEncoding="utf-8"%>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=BIG5">
  <title>第一個DWR程式</title>
  <script type='text/javascript' src='dwr/interface/HelloJS1.js'></script>
  <script type='text/javascript' src='dwr/engine.js'></script>
  <script type='text/javascript' src='dwr/util.js'></script>
  <script type='text/javascript' src='HelloJS.js'></script>
 </head>
 <body>
  <input id="user" type="text" />
  <input type='button' value='哈囉' onclick='hello123();' />
  <div id="result"></div>
 </body>
</html>

HelloJS.js

function hello123() {
 var user = $("user").value;
 HelloJS1.hello456(user, callback);
}
function callback(msg) {
 DWRUtil.setValue("result", msg);
}

Hello.java

package wust;

public class Hello {
 public String hello456(String name) {
  return "哈囉!" + name + "!您的第一個DWR!";
 }
}


test.jsp->hello123()->HelloJS.js->HelloJS1->dwr.xml->wust.Hello->HelloJS.js->test.jsp

posted on 2007-12-10 14:16 hijackwust 阅读(485) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2007年12月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

导航

统计

常用链接

留言簿(6)

随笔档案(57)

友情链接

搜索

最新评论

阅读排行榜

评论排行榜