dwr入门

 

//官网参考地址: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(&quot;gtbTranslateElementCode&quot;); for (var p in attrs) { data.removeAttribute(p); } for (var p in attrs) { if (&quot;undefined&quot; != typeof attrs[p]) { data.setAttribute(p, attrs[p]); } } var evt = document.createEvent(&quot;Events&quot;); evt.initEvent(message, true, false); document.dispatchEvent(evt);}function checkLibReady (){ var ready = lib.isAvailable(); if (ready) { sendMessage(&quot;gtbTranslateLibReady&quot;, {&quot;gtbTranslateError&quot; : false}); return; } if (checkReadyCount++ &gt; 5) { sendMessage(&quot;gtbTranslateLibReady&quot;, {&quot;gtbTranslateError&quot; : true}); return; } setTimeout(checkLibReady, 100);}gtbTranslateOnElementLoaded = function () { lib = google.translate.TranslateService({}); sendMessage(&quot;{EVT_LOADED}&quot;, {}, []); var data = document.getElementById(&quot;gtbTranslateElementCode&quot;); data.addEventListener(&quot;gtbTranslate&quot;, onTranslateRequest, true); data.addEventListener(&quot;gtbTranslateCheckReady&quot;, onCheckReady, true); data.addEventListener(&quot;gtbTranslateRevert&quot;, onRevert, true); checkLibReady();};function onCheckReady() { var ready = lib.isAvailable(); sendMessage(&quot;gtbTranslateLibReady&quot;, {&quot;gtbTranslateError&quot; : !ready});}function onTranslateRequest() { var data = document.getElementById(&quot;gtbTranslateElementCode&quot;); var orig = data.getAttribute(&quot;gtbOriginalLang&quot;); var target = data.getAttribute(&quot;gtbTargetLang&quot;); lib.translatePage(orig, target, onProgress);}function onProgress(progress, opt_finished, opt_error) { sendMessage(&quot;gtbTranslateOnProgress&quot;, {&quot;gtbTranslateProgress&quot; : progress, &quot;gtbTranslateFinished&quot; : opt_finished, &quot;gtbTranslateError&quot; : opt_error});}function onRevert() { lib.restore();}})(); (function(){var d=window,e=document;function f(b){var a=e.getElementsByTagName(&quot;head&quot;)[0];a||(a=e.body.parentNode.appendChild(e.createElement(&quot;head&quot;)));a.appendChild(b)}function _loadJs(b){var a=e.createElement(&quot;script&quot;);a.type=&quot;text/javascript&quot;;a.charset=&quot;UTF-8&quot;;a.src=b;f(a)}function _loadCss(b){var a=e.createElement(&quot;link&quot;);a.type=&quot;text/css&quot;;a.rel=&quot;stylesheet&quot;;a.charset=&quot;UTF-8&quot;;a.href=b;f(a)}function _isNS(b){for(var b=b.split(&quot;.&quot;),a=d,c=0;c&lt;b.length;++c)if(!(a=a[b[c]]))return!1;return!0} function _setupNS(b){for(var b=b.split(&quot;.&quot;),a=d,c=0;c&lt;b.length;++c)a=a[b[c]]||(a[b[c]]={});return a}d.addEventListener&amp;&amp;typeof e.readyState==&quot;undefined&quot;&amp;&amp;d.addEventListener(&quot;DOMContentLoaded&quot;,function(){e.readyState=&quot;complete&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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的公寓报修管理系统,源码+数据库+毕业论文+视频演示 现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本公寓报修管理系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此公寓报修管理系统利用当下成熟完善的Spring Boot框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的MySQL数据库进行程序开发。公寓报修管理系统有管理员,住户,维修人员。管理员可以管理住户信息和维修人员信息,可以审核维修人员的请假信息,住户可以申请维修,可以对维修结果评价,维修人员负责住户提交的维修信息,也可以请假。公寓报修管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 关键词:公寓报修管理系统;Spring Boot框架;MySQL;自动化;VUE
毕业设计,基于SpringBoot+Vue+MySQL开发的社区医院管理系统,源码+数据库+毕业论文+视频演示 信息数据从传统到当代,是一直在变革当中,突如其来的互联网让传统的信息管理看到了革命性的曙光,因为传统信息管理从时效性,还是安全性,还是可操作性等各个方面来讲,遇到了互联网时代才发现能补上自古以来的短板,有效的提升管理的效率和业务水平。传统的管理模式,时间越久管理的内容越多,也需要更多的人来对数据进行整理,并且数据的汇总查询方面效率也是极其的低下,并且数据安全方面永远不会保证安全性能。结合数据内容管理的种种缺点,在互联网时代都可以得到有效的补充。结合先进的互联网技术,开发符合需求的软件,让数据内容管理不管是从录入的及时性,查看的及时性还是汇总分析的及时性,都能让正确率达到最高,管理更加的科学和便捷。本次开发的社区医院管理系统实现了病例信息、字典表、家庭医生、健康档案、就诊信息、前台、药品、用户、用户、用户表等功能。系统用到了关系型数据库中王者MySql作为系统的数据库,有效的对数据进行安全的存储,有效的备份,对数据可靠性方面得到了保证。并且程序也具备程序需求的所有功能,使得操作性还是安全性都大大提高,让社区医院管理系统更能从理念走到现实,确确实实的让人们提升信息处理效率。 关键字:社区医院管理系统;信息管理,时效性,安全性,MySql
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值