`
lyunabc
  • 浏览: 563323 次
  • 性别: Icon_minigender_2
社区版块
存档分类
最新评论

DWR入门

 
阅读更多

摘自:http://directwebremoting.org/dwr/introduction/getting-started.html

Getting Started with DWR

There are several ways to get started withDWR. We recommend the following:

Follow the 5 steps outlined below.

Download the dwr.war file and experimentwith the examples.

Once DWR is up and running learn how towrite JavaScript for DWR.

DWR in 5 steps

1. Install the DWR JAR file

Download the dwr.jar file. Place it intothe WEB-INF/lib directory of your web application.

2. Install the Commons Logging JAR file

DWR depends on Commons Logging. Downloadthe commons-logging.jar and place it into the WEB-INF/lib directory of your webapplication.

3. Add the DWR servlet definition andmapping to your application's web.xml

Add the following lines to your webapplication's deployment descriptor (WEB-INF/web.xml). The <servlet>section needs to go with any existing <servlet> sections, and likewisewith the <servlet-mapping> section.

<servlet>

<display-name>DWR Servlet</display-name>

<servlet-name>dwr-invoker</servlet-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>

4. Create the DWR configuration file(dwr.xml)

Create a new file in you web application'sWEB-INF directory (alongside web.xml) named dwr.xml.

A simple way to start is with somethinglike this:

<!DOCTYPE dwr PUBLIC

"-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN"

"http://getahead.org/dwr/dwr30.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>

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

The new creator that we used above uses thepublic no-args constructor that all Java Beans must have. It is also worthremembering that DWR has one restriction:

Avoid reserved JavaScript words; Methodsnamed after reserved words are automatically excluded. Most JavaScript reservedwords 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 in JavaScript but not Java.

Visit the dwr.xml documentation for adetailed description of the dwr.xml file, creators and converters.

5. Take DWR for a test drive!

Go to the following URL:

http://localhost:8080/[YOUR-WEBAPP-CONTEXT]/dwr/

You should see a page showing you theclasses you configured in Step 4. Having followed a link you should see anindex of all the methods ready for calling - simply enter the requiredparameters (if parameters are required) and click the execute button. Thesepages are valuable debugging tools and dynamically generated by DWR when thedebug init-param is set to true.

How to make use of this from your webapplication

We have a whole section on writingJavascript with DWR, and there are a number of examples in the sidebar thatdemonstrate how to dynamically alter the text in web pages, update lists,manipulate forms and perform live table editing. Each has a description of howit works.

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

Go tohttp://localhost:8080/[YOUR-WEBAPP-CONTEXT]/dwr/ and click on your class

View source and find the line that executesthe method that you are interested in.

Paste the text into an HTML or JSP page inyour web-app.

Include links to the DWR JavaScript filesthat make the magic happen:

<scriptsrc='/[YOUR-WEBAPP-CONTEXT]/dwr/interface/[YOUR-SCRIPT].js'></script>

<scriptsrc='/[YOUR-WEBAPP-CONTEXT]/dwr/engine.js'></script>

You can omit the /[YOUR-WEBAPP-CONTEXT]/section and use relative paths in your web pages if you wish.

Next Step: Learn about writing Javascriptthat interacts with DWR.

What if it doesn't work?

We have a page containing troubleshootingadvice and common problems and their fixes. This is the first place to look.


分享到:
评论

相关推荐

    Dwr入门操作手册Dwr

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

    dwr入门 dwr学习资料

    DWR(Direct Web Remoting)是一...通过学习这套DWR入门资料,你将能够熟练地使用DWR创建动态、交互性强的Web应用,提高开发效率,同时提升用户体验。实践中不断探索,理论与实战相结合,将助你在Web开发领域更进一步。

    dwr API dwr入门教程

    在DWR入门教程中,首先会介绍DWR的基本概念和工作原理。DWR的核心是将Java方法暴露给JavaScript,通过在服务器端创建一个称为"逆向Ajax"的通道,使得JavaScript能够调用远程服务器上的Java方法。这个过程涉及到几个...

    DWR中文文档 dwr入门 dwr.jar

    **DWR入门步骤:** 1. **引入依赖**:首先,你需要在项目中添加dwr.jar到类路径中,这将包含所有DWR运行所需的类和库。 2. **配置DWR**:在Web应用的Web-INF目录下创建dwr.xml配置文件,设置允许的远程接口和方法...

    DWR+dwr入门手册

    在"DWR+dwr入门手册"中,你将深入了解到以下几个核心知识点: 1. **DWR的基本概念**:DWR的核心是Remoting Engine,它负责在客户端JavaScript和服务器端Java之间建立通信通道。DWR提供了一套API,包括`dwr.engine`...

    Ajax的DWR入门例子

    3. **DWR入门步骤**: - **准备环境**:首先,需要下载DWR的jar包,如dwrc.jar,将其放入项目的lib目录下。 - **创建Web项目**:创建一个新的Web项目,例如名为sayHello。 - **编写Java类**:创建一个名为...

    DWR入门例子(一个很好的dwr入门例子)

    在这个"DWR入门例子"中,我们将深入探讨如何使用DWR进行服务器和客户端之间的数据交换。 1. **DWR基本概念** - **反向AJAX**: DWR的核心理念是反向AJAX,即由服务器主动向客户端推送数据,而不仅仅是响应客户端的...

    软件工程DWR入门教程.docx

    软件工程 DWR 入门教程 DWR(Direct Web Remoting)是一种基于 Java 的远程方法调用技术,它允许在 Web 应用程序中将 Java 对象作为远程服务暴露给客户端,客户端可以通过 Ajax 调用这些服务。下面是 DWR 入门教程...

    STRUT2 DWR 入门STRUT2 DWR 入门STRUT2 DWR 入门STRUT2 DWR 入门

    STRUT2 DWR入门教程 DWR(Direct Web Remoting)是一种开源JavaScript库,它允许在Web应用程序中实现Ajax功能,使用户界面更加动态和交互性更强。与STRUT2框架结合使用,DWR可以为Java后端提供简单且高效的远程方法...

    Dwr入门操作手册

    《DWR入门操作手册》深度解析与实践指南 一、DWR配置与使用基础 DWR,全称为Direct Web Remoting,是一种使Java对象能够直接从JavaScript调用的技术,简化了Ajax开发流程,使得前后端交互更为直接和高效。本文档...

    Dwr入门操作手册及dwr包

    **DWR(Direct Web Remoting)入门操作手册及DWR包** DWR,全称Direct Web Remoting,是一个...通过深入学习"Dwr入门操作手册"并实践使用"dwr.jar",你可以掌握如何利用DWR构建交互性更强、用户体验更好的Web应用。

    最完整的DWR入门文档及DWR使用案例

    这个“最完整的DWR入门文档及DWR使用案例”包含的资源无疑将帮助你深入理解和高效使用DWR。 首先,DWR的核心功能是提供了一种跨域的通信机制,使得前端JavaScript可以直接调用后端Java方法,就像操作本地函数一样,...

    DWR入门程序(1.0和3.0版本的测试工程)

    在"DWR入门程序--计算两个数之和及包含页面的例子(使用1.0版本).rar"中,我们可以看到一个简单的例子,展示了如何使用DWR 1.0进行数据交互。这个例子可能包括一个HTML页面,该页面包含一个JavaScript函数,该函数...

    dwr入门例子 返回list

    在“dwr入门例子 返回list”这个主题中,我们将深入探讨如何使用DWR从服务器返回列表数据到客户端。列表通常包含多个项目,如数据库查询结果,这些数据可以在网页上以表格或其他形式展示给用户。DWR提供了方便的方法...

    dwr实例 - dwr入门 本人开发的:小游戏 大家一起来赚钱

    DWR入门涉及以下几个关键知识点: 1. **配置DWR**:首先,你需要在项目中集成DWR,这通常包括在`web.xml`中配置DWR的Servlet,以及在项目的类路径下创建`dwr.xml`配置文件,用于声明暴露给JavaScript的Java类和方法...

    dwr入门资料,简单入门,让你轻松掌握dwr

    在"**dwr入门资料,简单入门,让你轻松掌握dwr**"的资源中,你可以期待学习到以下关键知识点: 1. **DWR的基本概念**:理解DWR的核心概念,如Remoting、Reverse Ajax和Caching,以及如何通过DWR实现浏览器与服务器...

    DWR入门教程及实例(含源代码)

    本教程“DWR入门教程及实例(含源代码)”旨在帮助初学者快速掌握DWR的基本概念和使用方法。教程内容可能包括以下几个核心知识点: 1. **DWR概述**:讲解DWR的基本理念,如何通过HTTP协议实现JavaScript与Java之间...

    个人编写的一份dwr入门源代码

    这份"个人编写的一份dwr入门源代码"是针对初学者设计的,通过五个简单示例帮助理解DWR的基本用法和功能。 1. **DWR简介**:DWR简化了AJAX开发,通过自动处理跨域问题和JSON/JavaScript对象转换,使得前端可以像调用...

    dwr入门例子 包含类型转换

    以上就是DWR入门例子中关于类型转换的基本使用。通过DWR,开发者可以轻松地实现前后端的数据交换,从而创建更动态、响应更快的Web应用。需要注意的是,实际项目中还需要考虑安全性、性能优化以及错误处理等问题。

Global site tag (gtag.js) - Google Analytics