`
marscom
  • 浏览: 28289 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论
阅读更多
http://getahead.org/dwr/getstarted

Getting Started with DWR
There are 2 ways to get started with DWR, the easy way is to download the WAR file and have a look around, however this does not help you see how easily DWR integrates with your current web application, so the following 3 simple steps are recommended:

1. Install the DWR JAR file
Download the dwr.jar file. Place it in the WEB-INF/lib directory of your webapp. You'll probably have a set of jar files in there already. From version 2.0, DWR also requires commons-logging.

2. Edit the config files
The following lines need to be added to WEB-INF/web.xml. The <servlet> section needs to go with the other <servlet> sections, and likewise with the <servlet-mapping> section.

<servlet>
  <servlet-name>dwr-invoker</servlet-name>
  <display-name>DWR Servlet</display-name>
  <servlet-class>org.directwebremoting.servlet.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>
If you are using DWR 1.x then the servlet-class line should contain the following: uk.ltd.getahead.dwr.DWRServlet. The 1.x version will still work with 2.x, but the new one is preferred.

Then create a dwr.xml file that lives in WEB-INF alongside web.xml. A simple way to start is with something like this:

<!DOCTYPE dwr PUBLIC
    "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
    "http://getahead.org/dwr/dwr20.dtd">

<dwr>
  <allow>
    <create creator="new" javascript="JDate">
      <param name="class" value="java.util.Date"/>
    </create>
    <create creator="new" javascript="Demo">
      <param name="class" value="your.java.Bean"/>
    </create>
  </allow>
</dwr>
Obviously, if you are using version 1.x the opening line will have 1.0 in place of 2.0 and 10 in place of 20.

The DWR config file defines what classes DWR can create and remote for use by Javascript. In the example above we are defining 2 classes that are remoted and giving the classes names in Javascript.

The new creator that we used above uses the public no-args constructor that all JavaBeans must have. It is also worth remembering that DWR has a few restrictions:

Avoid reserved JavaScript words; Methods named after reserved words are automatically excluded. Most JavaScript reserved words are also Java reserved words, so you won't be having a method called "try()" anyway. However the most common gotcha is "delete()", which has special meaning from JavaScript but not Java.
Overloaded methods can be involved in a bit of a lottery as to which gets called, so avoid overloaded methods.
3. Go to the following URL
http://localhost:8080/[YOUR-WEBAPP]/dwr/
You should see a page showing you the classes that you've selected in step 2. Having followed a link you should see an index of all the methods all ready for calling. These pages are dynamically generated examples of what you can do using DWR.

Kick the tyres and have a look around.

How to make use of this from your web application
There are a number of examples in the sidebar that demonstrate how to dynamically alter the text in web pages, update lists, manipulate forms and do live table editing. Each has a description of how it works.

Another way to get started is to look at the source from the pages that you just viewed:

Go to http://localhost:8080/[YOUR-WEBAPP]/dwr/ and click on you class
View source and find the line that executes the method that you are interested in.
Paste the text into an HTML or JSP page in your web-app.
Include links to the javascript files that make the magic happen:
<script src='/[YOUR-WEBAPP]/dwr/interface/[YOUR-SCRIPT].js'></script>
<script src='/[YOUR-WEBAPP]/dwr/engine.js'></script>
You can omit the /[YOUR-WEBAPP]/ section and use relative paths in your web pages if you wish.

For more information about how to write Javascript that interacts with DWR see the scripting introduction.

What if it doesn't work?
We have a log of common problems and their fixes. This is the first place to look.

If you are still having problems please join the mailing list and ask there.


分享到:
评论
1 楼 itlangqun 2009-01-06  
这样没意义....
要是楼主能加点自己的评论就好很多,呵呵.....

相关推荐

    dwr源码包,dwr.jar包下载

    1、 导入dwr.jar包 2、 在web.xml中配置dwr,如下: &lt;!-- 配置DWR --&gt; &lt;servlet-name&gt;dwr-invoker org.directwebremoting.servlet.DwrServlet &lt;init-param&gt; &lt;param-name&gt;debug&lt;/param-name&gt; ...

    dwr所需要的jar包

    DWR (Direct Web Remoting) 是一个开源Java库,它允许Web应用程序在浏览器和服务器之间进行实时通信,无需使用插件或复杂的JavaScript框架。DWR简化了AJAX(Asynchronous JavaScript and XML)开发,使开发者可以像...

    dwr实例,从后台取数据显示

    Direct Web Remoting (DWR) 是一种开源的Java库,它允许JavaScript在浏览器端与服务器端的Java对象进行交互,从而实现动态Web应用程序。DWR的主要功能是通过AJAX技术在客户端和服务器之间进行实时通信,使得用户界面...

    DWR3实现服务器端向客户端精确推送消息

    DWR(Direct Web Remoting)是一种Java库,它允许JavaScript在Web浏览器中直接调用Java方法,从而实现实时的、双向的通信。在“DWR3实现服务器端向客户端精确推送消息”这一主题中,我们将深入探讨如何利用DWR3进行...

    DWR.xml配置文件说明书(含源码)

    DWR.xml配置文件说明书 1、 建立dwr.xml 配置文件 任何一个dwr.xml的文件都需要包含DWR DOCTYPE的声明行,格式如下: &lt;!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" ...

    DWR中文文档DWR

    DWR(Direct Web Remoting)是一种Java库,它允许JavaScript在客户端与服务器端进行直接的交互,从而实现在Web应用程序中的Ajax功能。DWR的主要目标是简化前后端的数据交换,提高用户体验,使得Web应用能够像桌面...

    DWR实现的新消息定时提醒

    DWR(Direct Web Remoting)是一种JavaScript库,它允许JavaScript代码在客户端与服务器端进行直接交互,从而实现实时Web应用程序。在这个特定的场景中,我们利用DWR来实现一个新消息的定时提醒功能,这在许多Web...

    DWR(包括engine.js+util.js).rar

    这个压缩包包含了DWR的核心组件`engine.js`和辅助库`util.js`,它们是实现DWR功能的关键。 `engine.js`是DWR的核心脚本,它实现了JavaScript和Java之间的远程调用(Remote Procedure Calls, RPC)。这个文件处理了...

    dwr和简单的文件上传

    DWR (Direct Web Remoting) 是一个开源的Java库,它允许JavaScript在浏览器端与服务器端的Java对象进行交互,实现动态的Web应用。在这个场景中,我们将讨论如何使用DWR来实现简单的文件上传功能。 文件上传是Web...

    DWR 初始,返回字符串&对象&列表

    DWR(Direct Web Remoting)是一种JavaScript到Java的远程调用技术,允许Web应用程序在客户端与服务器之间进行实时通信,而无需刷新整个页面。DWR的出现极大地提升了Web应用的用户体验,因为它允许开发者在前端与...

    dwr的例子 反向AJAX 实现时时提醒

    Direct Web Remoting (DWR) 是一个开源Java库,它允许在浏览器和服务器之间进行安全、高效的异步通信,即所谓的“反向AJAX”或“Comet”技术。DWR使得JavaScript能够调用服务器端的Java方法,就像它们是本地函数一样...

    dwr笔记 dwr自学资料

    DWR (Direct Web Remoting) 是一种开源Java技术,它允许Web应用程序在浏览器和服务器之间进行实时、双向通信,使得JavaScript可以直接调用服务器端的Java方法,极大地简化了客户端和服务器端的数据交换。本笔记将...

    dwr实现ajax功能ajax+dwr

    **DWR(Direct Web Remoting)**是一种Java技术,它允许Web应用程序在客户端与服务器之间进行实时通信,而无需刷新整个页面。通过DWR,我们可以使用JavaScript直接调用服务器端的Java方法,实现Ajax(Asynchronous ...

    dwr demo dwr简单使用

    DWR (Direct Web Remoting) 是一个开源的Java库,它允许JavaScript在浏览器端与服务器端的Java对象进行交互,实现动态的Web应用。DWR简化了AJAX(Asynchronous JavaScript and XML)的开发,使得开发者可以像调用...

    springboot整合dwr实现js调用java方法

    SpringBoot整合Direct Web Remoting (DWR)是一个常见的技术实践,它允许JavaScript在浏览器端直接调用服务器端的Java方法,极大地增强了Web应用的交互性。在这个过程中,我们通常会结合使用FreeMarker或JSP作为视...

    springMVC+dwr技术实现消息推送实例

    SpringMVC 和 DWR(Direct Web Remoting)是两种在Web开发中用于增强交互性的技术。SpringMVC作为Spring框架的一部分,主要用于构建后端服务,而DWR则是一种JavaScript库,允许JavaScript与Java服务器进行实时通信,...

    dwr1+dwr2+dwr3 jar包

    这个压缩包包含了DWR的三个主要版本:DWR1.0、DWR2.0和DWR3.0的jar包,这些jar包是运行DWR应用的核心组件。 DWR1.0: DWR1.0是DWR项目的早期版本,主要目标是简化Web应用中的异步通信。在这个版本中,DWR提供了一个...

    DWR3.0.jar、DWR.war和DWR2.0中文说明文档

    这个压缩包包含了DWR的三个关键组件:DWR3.0.jar,DWR的实例war文件,以及DWR2.0的中文说明文档。以下是关于这些组件的详细知识: 1. **DWR3.0.jar**: DWR3.0.jar是DWR框架的核心库,包含所有必需的类和接口,...

    使用dwr+spring实现消息推送

    在本教程中,我们将探讨如何利用Direct Web Remoting (DWR) 和Spring框架来实现这样的功能。 DWR是一个开源Java库,它允许Web应用程序在浏览器和服务器之间进行实时的、异步的通信,类似于Ajax的功能,但更加强大。...

Global site tag (gtag.js) - Google Analytics