dwr的配置文件+简单的例子

web.xml文件的配置信息

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
  <display-name>  ajaxDWR</display-name>
   <servlet>   
   <servlet-name>dwr-invoker</servlet-name>   
   <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>   
   <init-param>     
   <description>     
   </description>     
   <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>
  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

dwr文件的配置信息

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://getahead.org/dwr//dwr30.dtd">
<dwr>
 <allow>
  <create creator="new" javascript="Hello">
   <param name="class" value="extdwr.Hello" />
  </create>
 </allow>
</dwr>

helloword的Java文件

 

package extdwr;

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

}

 

 

dwrhello的jsp文件

 

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
   + request.getServerName() + ":" + request.getServerPort()
   + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=BIG5">
  <title>第一個DWR程式</title>
  <script type='text/javascript' src='dwr/interface/Hello.js'></script>
  <script type='text/javascript' src='dwr/engine.js'></script>
  <script type='text/javascript' src='dwr/util.js'></script>
  <script type="text/javascript">
  function hello() {  
   var user = $('user').value;  
    Hello.hello(user, callback);
    }
    function callback(msg) {
   document.getElementById("result").innerHTML = msg;
      }
  
  </script>
 </head>
 <body>
  <input id="user" type="text" />
  <input type='button' value='哈囉' οnclick='hello();' />
  <div id="result"></div>
 </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值