`
iloveoracle
  • 浏览: 118730 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

dwr入门

    博客分类:
  • java
阅读更多
     
//官网参考地址:http://directwebremoting.org/dwr/index.html
 
<h1 style="font-size: 150%;">direct web remoting</h1>dwr is a java library that enables java on the server and javascript in a browser to interact and call each other as simply as possible.
dwr is easy ajax for java
 
 
dwr will generate the javascript to allow web browsers to securely call into java code almost as if it was running locally. it can marshal virtually any data including collections, pojos, xml and binary data like images and pdf files. all that is required is a security policy that defines what is allowed.
with reverse ajax, dwr allows java code running on a server to use client side apis to publish updates to arbitrary groups of browsers. this allows interaction 2 ways - browser calling server and server calling browser. dwr supports comet, polling and piggyback (sending data in with normal requests) as ways to publish to browsers.
dwr provides integration with spring, struts, guice, hibernate and others.
 
 
dwr is a rpc library which makes it easy to call java functions fromjavascript and to call javascript functions from java (a.k.a reverseajax).
 
 
dwr consists of two main parts:
  • a java servlet running on the server that processes requests andsends responses back to the browser.
  • javascript running in the browser that sends requests and candynamically update the webpage.
dwr works by dynamically generating javascript based on javaclasses. the code does some ajax magic to make it feel like theexecution is happening on the browser, but in reality the server isexecuting the code and dwr is marshalling the data back and forwards.
 
this method of remoting functions from java to javascript gives dwrusers a feel much like conventional rpc mechanisms like rmi or soap,with the benefit that it runs over the web without requiringweb-browser plug-ins.
 
<pre><create creator="new" javascript="jdate">      <param name="class" value="java.util.date"/>    </create></pre> 
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 one restriction:
  • 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 in javascript but not java.
visit the dwr.xml documentation for a detailed description of the dwr.xml file, creators and converters.
 
the javascript attribute is required - it gives your newly created object a name in the browser. you should avoid using javascript reserved words.
the scope attribute is largely the same as the scope attribute as defined by the servlet spec. it allows you to specify what a bean is available to. the options are "application", "session", "request", "page" and an additional scope "script". the first 4 of these values should be familiar to servlet and jsp developers. "script" scope allows you to have something similar to an http session that is tied to an id in a page rather than in a cookie.
the scope attribute is optional. it defaults to "page".
 
dwr comes with some small javascript libraries to help you:
  • engine.js: handles allserver communication
  • util.js: helps you alterweb pages with the data you got from the server (and a few neat extrastoo)
//配置(注意版本)
http://directwebremoting.org/dwr/introduction/getting-started.html
//http://directwebremoting.org/dwr/documentation/browser/util/addoptions.html
//http://directwebremoting.org/dwr/documentation/browser/util/lists.html
//例子
下载2.0版本
根据下载的版本配置,也可根据上面来配置,但官网上配置的版本是3.0的,所以dwr.xml需从2.0中得到dtd。
 
重点是下载中的例子
在eclipse中运行项目,找出下面的内容(其中1、3是要掌握的,2一般少用):
tutorial style examples in this war file:
  • dynamic text: a very simple documented example that updates a page with some text.
  • resource forwarding: how to dynamically include the contents of one page in another.
  • editable table: another simple documented example that allows the user to edit a table of data.
以上的例子需理解其中的源码,尤其是编辑表格。
<script id="gtbtranslateelementcode">var gtbtranslateonelementloaded;(function(){var lib = null;var checkreadycount = 0;function sendmessage(message, attrs) {  var data = document.getelementbyid(&amp;quot;gtbtranslateelementcode&amp;quot;);  for (var p in attrs) {    data.removeattribute(p);  }  for (var p in attrs) {    if (&amp;quot;undefined&amp;quot; != typeof attrs[p]) {      data.setattribute(p, attrs[p]);    }  }  var evt = document.createevent(&amp;quot;events&amp;quot;);  evt.initevent(message, true, false);  document.dispatchevent(evt);}function checklibready (){  var ready = lib.isavailable();  if (ready) {    sendmessage(&amp;quot;gtbtranslatelibready&amp;quot;, {&amp;quot;gtbtranslateerror&amp;quot; : false});    return;  }  if (checkreadycount++ &amp;gt; 5) {    sendmessage(&amp;quot;gtbtranslatelibready&amp;quot;, {&amp;quot;gtbtranslateerror&amp;quot; : true});    return;  }  settimeout(checklibready, 100);}gtbtranslateonelementloaded = function () {  lib = google.translate.translateservice({});  sendmessage(&amp;quot;{evt_loaded}&amp;quot;, {}, []);  var data = document.getelementbyid(&amp;quot;gtbtranslateelementcode&amp;quot;);  data.addeventlistener(&amp;quot;gtbtranslate&amp;quot;, ontranslaterequest, true);  data.addeventlistener(&amp;quot;gtbtranslatecheckready&amp;quot;, oncheckready, true);  data.addeventlistener(&amp;quot;gtbtranslaterevert&amp;quot;, onrevert, true);  checklibready();};function oncheckready() {  var ready = lib.isavailable();  sendmessage(&amp;quot;gtbtranslatelibready&amp;quot;, {&amp;quot;gtbtranslateerror&amp;quot; : !ready});}function ontranslaterequest() {  var data = document.getelementbyid(&amp;quot;gtbtranslateelementcode&amp;quot;);  var orig = data.getattribute(&amp;quot;gtboriginallang&amp;quot;);  var target = data.getattribute(&amp;quot;gtbtargetlang&amp;quot;);  lib.translatepage(orig, target, onprogress);}function onprogress(progress, opt_finished, opt_error) {  sendmessage(&amp;quot;gtbtranslateonprogress&amp;quot;, {&amp;quot;gtbtranslateprogress&amp;quot; : progress,       &amp;quot;gtbtranslatefinished&amp;quot; : opt_finished, &amp;quot;gtbtranslateerror&amp;quot; : opt_error});}function onrevert() {  lib.restore();}})(); (function(){var d=window,e=document;function f(b){var a=e.getelementsbytagname(&amp;quot;head&amp;quot;)[0];a||(a=e.body.parentnode.appendchild(e.createelement(&amp;quot;head&amp;quot;)));a.appendchild(b)}function _loadjs(b){var a=e.createelement(&amp;quot;script&amp;quot;);a.type=&amp;quot;text/javascript&amp;quot;;a.charset=&amp;quot;utf-8&amp;quot;;a.src=b;f(a)}function _loadcss(b){var a=e.createelement(&amp;quot;link&amp;quot;);a.type=&amp;quot;text/css&amp;quot;;a.rel=&amp;quot;stylesheet&amp;quot;;a.charset=&amp;quot;utf-8&amp;quot;;a.href=b;f(a)}function _isns(b){for(var b=b.split(&amp;quot;.&amp;quot;),a=d,c=0;c&amp;lt;b.length;++c)if(!(a=a[b[c]]))return!1;return!0}function _setupns(b){for(var b=b.split(&amp;quot;.&amp;quot;),a=d,c=0;c&amp;lt;b.length;++c)a=a[b[c]]||(a[b[c]]={});return a}d.addeventlistener&amp;amp;&amp;amp;typeof e.readystate==&amp;quot;undefined&amp;quot;&amp;amp;&amp;amp;d.addeventlistener(&amp;quot;domcontentloaded&amp;quot;,function(){e.readystate=&amp;quot;complete&amp;quot;},!1);if (_isns('google.translate.element')){return}var c=_setupns('google.translate._const');c._cl='zh-cn';c._cuc='gtbtranslateonelementloaded';c._cac='';c._cam='lib';var h='translate.googleapis.com';var b=(window.location.protocol=='https:'?'https://':'http://')+h;c._pah=h;c._pbi=b+'/translate_static/img/te_bk.gif';c._pci=b+'/translate_static/img/te_ctrl3.gif';c._phf=h+'/translate_static/js/element/hrs.swf';c._pli=b+'/translate_static/img/loading.gif';c._plla=h+'/translate_a/l';c._pmi=b+'/translate_static/img/mini_google.png';c._ps=b+'/translate_static/css/translateelement.css';c._puh='translate.google.com';_loadcss(c._ps);_loadjs(b+'/translate_static/js/element/main_zh-cn.js');})();</script>
 
0
2
分享到:
评论

相关推荐

    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`...

    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方法,就像操作本地函数一样,...

    Ajax的DWR入门例子

    3. **DWR入门步骤**: - **准备环境**:首先,需要下载DWR的jar包,如dwrc.jar,将其放入项目的lib目录下。 - **创建Web项目**:创建一个新的Web项目,例如名为sayHello。 - **编写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入门教程之HelloWorld

    在本“DWR入门教程之HelloWorld”中,我们将逐步学习如何搭建一个简单的DWR应用,体验其基本功能。首先,我们需要了解以下关键组件: 1. **配置DWR**: 在Web应用程序的`web.xml`文件中,我们需要添加DWR的Servlet...

Global site tag (gtag.js) - Google Analytics