`
gmingsoft04
  • 浏览: 6952 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
最近访客 更多访客>>
社区版块
存档分类
最新评论

Getting Started with DWR

    博客分类:
  • DWR
阅读更多
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
We have a whole section on writing Javascript with DWR, and 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.

Next Step: Learn about writing Javascript that interacts with DWR.

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.

分享到:
评论

相关推荐

    DWR-Getting Started.pdf

    - 访问DWR官方网站(http://getahead.org/dwr/getstarted)下载`dwr.jar`。 - 确保下载的是适合当前项目版本的DWR JAR文件。 2. **放置JAR文件**: - 将下载好的`dwr.jar`文件放入项目的`WEB-INF/lib`目录下。 ...

    dwr dwrdwr

    dwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwr

    DWR中文文档DWR

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

    dwr笔记 dwr自学资料

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

    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 demo dwr简单使用

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

    dwr实现ajax功能ajax+dwr

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

    DWR的学习资料,DWR学习必备

    DWR(Direct Web Remoting)是一种Java库,用于在Web应用程序中实现实时的JavaScript到服务器端Java对象的通信。这个技术允许开发者在浏览器中直接调用服务器端的方法,极大地简化了AJAX(Asynchronous JavaScript ...

    dwr1+dwr2+dwr3 jar包

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

    Dwr入门操作手册Dwr

    Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr...

    DWR配置文件详解,DWR配置

    **DWR配置文件详解** Direct Web Remoting (DWR) 是一种开源的Java库,它允许Web应用程序在客户端JavaScript和服务器端Java之间进行双向通信。DWR的核心配置文件是`dwr.xml`,该文件定义了DWR允许访问的Java对象、...

    dwr2.0 dwr3.0 jar包

    DWR(Direct Web Remoting)是一个开源的Java库,它为Web应用程序提供了强大的Ajax功能。通过DWR,前端JavaScript可以直接调用后端Java方法,从而实现动态、实时的Web交互,提升用户体验。这个主题主要围绕DWR的两个...

    dwr.jar 以及dwr配置文件

    Direct Web Remoting (DWR) 是一个开源的Java库,它允许在JavaScript和服务器端Java之间进行双向通信,实现Web应用程序的Ajax功能。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 教程 中文API DWR.xml配置文件说明 DWR学习笔记

    DWR(Direct Web Remoting)是一种Java库,用于在Web应用程序中实现JavaScript和服务器端Java代码之间的双向通信。这个教程包含了一系列的文档和资源,帮助开发者深入理解和使用DWR。 首先,"DWR学习笔记"提供了对...

    DWR中文文档 (DWR 2.0)

    ### DWR中文文档知识点概述 #### 一、DWR简介 **DWR(Direct Web Remoting)** 是一个开源的类库,旨在帮助开发者轻松构建包含AJAX技术的网站。其核心价值在于允许浏览器中的JavaScript代码能够直接调用运行在Web...

    dwr所需要的jar包

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

    DWR中文教程(外带DWR包)

    DWR(Direct Web Remoting)是一种Java库,用于在Web应用程序中实现实时的JavaScript到服务器端Java对象的通信。这个“DWR中文教程(外带DWR包)”为初学者提供了一个全面的入门指南,帮助理解并掌握DWR的基本概念和...

    DWR介绍

    ### DWR介绍 #### 一、DWR概述 DWR(Direct Web Remoting)是一种用于简化客户端JavaScript调用服务器端Java方法的技术。它通过Ajax技术实现了网页上的JavaScript直接调用服务器端的Java对象,极大地提高了Web应用...

Global site tag (gtag.js) - Google Analytics