dwr 学习笔记1

简单例子:

HTML source:

<p>
Name:
<input type="text" id="demoName"/>
<input value="Send" type="button" onclick="update()"/>
<br/>
Reply: <span id="demoReply"></span>
</p>

Javascript source:

function update() {
var name = dwr.util.getValue("demoName");
Demo.sayHello(name, function(data) {
dwr.util.setValue("demoReply", data);
});
}

Java source:

package org.getahead.dwrdemo.simpletext;
public class Demo {
public String sayHello(String name) {
return "Hello, " + name;
}
}

dwr.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="Demo">
<param name="class" value="org.getahead.dwrdemo.simpletext.Demo"/>
</create>
</allow>
</dwr>
其他配置:
 1   web.xml: 

 <listener>
    <listener-class>org.directwebremoting.servlet.EfficientShutdownServletContextAttributeListener</listener-class>
  </listener>
  <listener>
    <listener-class>org.directwebremoting.servlet.EfficientShutdownServletContextListener</listener-class>
  </listener>
 
 
   <servlet>
    <servlet-name>dwr-invoker</servlet-name>

    <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>

    <!-- This should NEVER be present in live -->
    <init-param>
      <param-name>debug</param-name>
      <param-value>true</param-value>
    </init-param>

    <!-- Remove this unless you want to use active reverse ajax -->
    <init-param>
      <param-name>activeReverseAjaxEnabled</param-name>
      <param-value>true</param-value>
    </init-param>

    <!-- By default DWR creates application scope objects when they are first
    used. This creates them when the app-server is started -->
    <init-param>
      <param-name>initApplicationScopeCreatorsAtStartup</param-name>
      <param-value>true</param-value>
    </init-param>

    <!-- This enables full streaming mode. It's probably better to leave this
    out if you are running across the internet -->
    <init-param>
      <param-name>maxWaitAfterWrite</param-name>
      <param-value>-1</param-value>
    </init-param>

    <!--
    For more information on these parameters, see:
    - http://getahead.org/dwr/server/servlet
    - http://getahead.org/dwr/reverse-ajax/configuration
    -->

    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>dwr-invoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
  </servlet-mapping>

2 js文件引入,因为我页面代码放在了index.jsp里面。所以引入js的代码如下:
  <script type='text/javascript' src='./tabs/tabs.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='./dwr/interface/Demo.js'> </script>
  应该建立一个项目路径。在所有文件里使用统一的路径。

posted on 2008-10-15 23:18 deepbluesea 阅读(292) 评论(0)  编辑  收藏 所属分类: JS


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


网站导航:
 
<2008年10月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

公告

MSN:zzlljj8833@hotmail.com lava:5832911

常用链接

留言簿(1)

随笔分类(9)

随笔档案(18)

文章分类(1)

文章档案(1)

搜索

最新评论

阅读排行榜

评论排行榜