首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

dwr小事例

2012-11-23 
dwr小例子web.xml文件的编写servletservlet-namedwr-invoker/servlet-name servlet-classuk.ltd.g

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>


添加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="Demo">          <param name="class" value="com.Demo"/>      </create>    </allow> </dwr> 


java类文件
package com;public class Demo {   public String sayHello(String name) {       return "Hello, " + name;    } }



html文件demo.xtml
    <title>Text Demo</title>   <script src='dwr/interface/Demo.js'></script>   <script src='dwr/engine.js'></script>   <script type='text/javascript' src='dwr/util.js'></script>  <script>        var allname;     function update()      {                 var name = dwr.util.getValue("demoName");        Demo.sayHello(name, function(data)          {              dwr.util.setValue("demoReply", data);              allname=data;         });         alert(allname);     }    </script>     </head>     <body>     <p> Name: <input type="text" id="demoName"/>               <input value="Send" type="button" onclick="update()"/>               <br/>         Reply: <span id="demoReply"></span>     </p>     </body>     </html>


<script type='text/javascript'  src='dwr/engine.js'></script>  
<script type='text/javascript'  src='dwr/interface/Demo.js'></script> 
<script type='text/javascript' src='dwr/util.js'></script> 

必须先导入 engine.js

热点排行