论坛首页 入门技术论坛

第一次配置dwr总结

浏览 1541 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-06-19  

[1]:在MyEclipse下创建一个web工程。

[2]:把准备好的dwr2.0.3.jar 拷贝到lib下。

[3]:修改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>DwrApp</display-name>
 <servlet>
  <servlet-name>dwr-invoker</servlet-name>
  <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
  <init-param>
   <description>dwr调试</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>

[4]:在web-inf下建立一个dwr.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
    "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
    "http://www.getahead.ltd.uk/dwr/dwr20.dtd">
<dwr>
  <allow>
    <create creator="new" javascript="Hello">
      <param name="class" value="test.DwrDemo"/>
    </create>
  </allow>
</dwr>
[5]:src下建立一个包test,然后建立一个class : DwrDemo

 

package test;
/**
 *
 * @author xp E-mail: xipei_1984@163.com
 * @version 创建时间:2009-6-19 上午12:01:41
 */
public class DwrDemo {
 public String message;
 public String sayHello(String message) {
  return "大家好:" + message;
 }
 public String getMessage() {
  return message;
 }
 public void setMessage(String message) {
  this.message = message;
 }
}
[6]:开始页面了吧:index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%String path = request.getContextPath();%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
      <script type="text/javascript" src="<%=path%>/dwr/interface/Hello.js"></script>
     <script type="text/javascript" src="<%=path%>/dwr/engine.js"></script>
     <script type="text/javascript" src="<%=path%>/dwr/util.js"></script>

    <!--这三个是dwr自动创建的,注意黑体与下面黑体的区别--->
     <script>
   function testDwr() {
    var hello = document.getElementById("hello").value;
    Hello.sayHello(hello, callBackHello);
   }
   
   function callBackHello(data) {
    alert(data);
   }
  </script>
  </head>
 
  <body>
    <input type="text" name="hello"><input type="button" value="submit" onclick="testDwr()">
  </body>
</html>

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics