//官网参考地址:http://directwebremoting.org/dwr/index.html
Direct Web Remoting
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 from
JavaScript and to call JavaScript functions from Java (a.k.a Reverse
Ajax).
DWR consists of two main parts:
- A Java Servlet running on the server that processes requests and
sends responses back to the browser.
- JavaScript running in the browser that sends requests and can
dynamically update the webpage.
DWR works by dynamically generating Javascript based on Java
classes. The code does some Ajax magic to make it feel like the
execution is happening on the browser, but in reality the server is
executing the code and DWR is marshalling the data back and forwards.
This method of remoting functions from Java to JavaScript gives DWR
users a feel much like conventional RPC mechanisms like RMI or SOAP,
with the benefit that it runs over the web without requiring
web-browser plug-ins.
<create creator="new" javascript="JDate">
<param name="class" value="java.util.Date"/>
</create>
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 all
server communication
-
util.js
: Helps you alter
web pages with the data you got from the server (and a few neat extras
too)
//配置(注意版本)
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("gtbTranslateElementCode"); for (var p in attrs) { data.removeAttribute(p); } for (var p in attrs) { if ("undefined" != typeof attrs[p]) { data.setAttribute(p, attrs[p]); } } var evt = document.createEvent("Events"); evt.initEvent(message, true, false); document.dispatchEvent(evt);}function checkLibReady (){ var ready = lib.isAvailable(); if (ready) { sendMessage("gtbTranslateLibReady", {"gtbTranslateError" : false}); return; } if (checkReadyCount++ > 5) { sendMessage("gtbTranslateLibReady", {"gtbTranslateError" : true}); return; } setTimeout(checkLibReady, 100);}gtbTranslateOnElementLoaded = function () { lib = google.translate.TranslateService({}); sendMessage("{EVT_LOADED}", {}, []); var data = document.getElementById("gtbTranslateElementCode"); data.addEventListener("gtbTranslate", onTranslateRequest, true); data.addEventListener("gtbTranslateCheckReady", onCheckReady, true); data.addEventListener("gtbTranslateRevert", onRevert, true); checkLibReady();};function onCheckReady() { var ready = lib.isAvailable(); sendMessage("gtbTranslateLibReady", {"gtbTranslateError" : !ready});}function onTranslateRequest() { var data = document.getElementById("gtbTranslateElementCode"); var orig = data.getAttribute("gtbOriginalLang"); var target = data.getAttribute("gtbTargetLang"); lib.translatePage(orig, target, onProgress);}function onProgress(progress, opt_finished, opt_error) { sendMessage("gtbTranslateOnProgress", {"gtbTranslateProgress" : progress, "gtbTranslateFinished" : opt_finished, "gtbTranslateError" : opt_error});}function onRevert() { lib.restore();}})(); (function(){var d=window,e=document;function f(b){var a=e.getElementsByTagName("head")[0];a||(a=e.body.parentNode.appendChild(e.createElement("head")));a.appendChild(b)}function _loadJs(b){var a=e.createElement("script");a.type="text/javascript";a.charset="UTF-8";a.src=b;f(a)}function _loadCss(b){var a=e.createElement("link");a.type="text/css";a.rel="stylesheet";a.charset="UTF-8";a.href=b;f(a)}function _isNS(b){for(var b=b.split("."),a=d,c=0;c<b.length;++c)if(!(a=a[b[c]]))return!1;return!0}
function _setupNS(b){for(var b=b.split("."),a=d,c=0;c<b.length;++c)a=a[b[c]]||(a[b[c]]={});return a}d.addEventListener&&typeof e.readyState=="undefined"&&d.addEventListener("DOMContentLoaded",function(){e.readyState="complete"},!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>
分享到:
相关推荐
DWR 入门DWR 入门DWR 入门DWR 入门DWR 入门欢迎使用 STRUT2 DWR 入门STRUT2 DWR 入门STRUT2 DWR 入门STRUT2 DWR 入门
Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr入门操作手册Dwr...
DWR入门操作手册DWR入门操作手册DWR入门操作手册DWR入门操作手册
软件工程 DWR 入门教程 DWR(Direct Web Remoting)是一种基于 Java 的远程方法调用技术,它允许在 Web 应用程序中将 Java 对象作为远程服务暴露给客户端,客户端可以通过 Ajax 调用这些服务。下面是 DWR 入门教程...
实例+说明 学完就会DWR dwr入门资料
DWR中文文档 dwr.jar dwr入门教程 很好的入门资料!!
dwr入门必看的资源,本人通过这个就很好的学习dwr
SSH CRM项目DWR入门源码(4)通过DWR实现动态树源码(5) var sjzdflArr; DWREngine.setAsync(false); SjzdflDAO.findAll(load); DWREngine.setAsync(true); function load...
dwr入门中web.xml配置 dwr.xml的位置和配置路径 ,附带测试小案例
最完整的DWR入门文档及DWR使用案例,让你轻松使用了解AJAX技术
dwr入门资料,简单入门,让你轻松掌握dwr
一个DWR入门教程,压缩包下有一个工程,直接在MYECLIPSE中导入工程,运行就可以,一个WORD文档介绍DWR的步骤
DWR入门教程及实例(含源代码),DWR的入门教程,jar文件夹中提供DWR所用jar包,运行源代码时需导入此文件夹中所有jar包
DWR入门教程.pdf
DWR入门程序---计算输入的两个数之和.rar DWR入门程序---计算输入的两个数之和.rar DWR入门程序---计算输入的两个数之和.rar
dwr实例 - 这是本人,开发的:小游戏 [大家一起来赚钱] 本例子可做为dwr入门级应用; 有什么问题请和我沟通;
DWR入门操作手册, 适用于DWR的初学者,很基础的,推荐新手下载
dwr入门例子 包含类型转换 dwr实战.doc
(网络整理资料)DWR入门与应用,手把手教你从配置到实例的应用