异步JavaScript技术和XML ( AJAX )与Java平台外文翻译资料

 2022-12-07 11:12

Asynchronous JavaScript Technology and XML (Ajax) With the Java Platform

By Greg Murray, June 9, 2005; updated October 2006

Article source : http://java.sun.com/developer/technicalArticles

Anyone who has used Flickr, GMail, Google Suggest, or Google Maps will realize that a new breed of dynamic web applications is emerging. These applications look and act very similar to traditional desktop applications without relying on plug-ins or browser-specific features. Web applications have traditionally been a set of HTML pages that must be reloaded to change any portion of the content. Technologies such as JavaScript programming language and cascading style sheets (CSS) have matured to the point where they can be used effectively to create very dynamic web applications that will work on all of the major browsers. This article will detail several techniques that you can use today to enable your web applications to be more rich and interactive like desktop applications.

Using JavaScript technology, an HTML page can asynchronously make calls to the server from which it was loaded and fetch content that may be formatted as XML documents, HTML content, plain text, or JavaScript Object Notation (JSON). The JavaScript technology may then use the content to update or modify the Document Object Model (DOM) of the HTML page. The term Asynchronous JavaScript Technology and XML (Ajax) has emerged recently to describe this interaction model.

Ajax is not new. These techniques have been available to developers targeting Internet Explorer on the Windows platform for many years. Until recently, the technology was known as web remoting or remote scripting. Web developers have also used a combination of plug-ins, Java applets, and hidden frames to emulate this interaction model for some time. What has changed recently is the inclusion of support for the XMLHttpRequest object in the JavaScript runtimes of the mainstream browsers. The real magic is the result of the JavaScript technologys XMLHttpRequest object. Although this object is not specified in the formal JavaScript technology specification, all of todays mainstream browsers support it. The subtle differences with the JavaScript technology and CSS support among current generation browsers such as Mozilla Firefox, Internet Explorer, and Safari are manageable. JavaScript libraries such as Dojo, Prototype, and the Yahoo User Interface Library have emerged to fill in where the browsers are not as manageable and to provide a standardized programming model. Dojo, for example, is addressing accessibility, internationalization, and advanced graphics across browsers -- all of which had been thorns in the side of earlier adopters of Ajax. More updates are sure to occur as the need arises.

What makes Ajax-based clients unique is that the client contains page-specific control logic embedded as JavaScript technology. The page interacts with the JavaScript technology based on events such as the loading of a document, a mouse click, focus changes, or even a timer. Ajax interactions allow for a clear separation of presentation logic from the data. An HTML page can pull in bite-size pieces to be displayed. Ajax will require a different server-side architecture to support this interaction model. Traditionally, server-side web applications have focused on generating HTML documents for every client event resulting in a call to the server. The clients would then refresh and re-render the complete HTML page for each response. Rich web applications focus on a client fetching an HTML document that acts as a template or container into which to inject content, based on client events using XML data retrieved from a server-side component.

Some uses for Ajax interactions are the following:

  • Real-time form data validation: Form data such as user IDs, serial numbers, postal codes, or even special coupon codes that require server-side validation can be validated in a form before the user submits a form. See Realtime Form Validation for details.
  • Autocompletion: A specific portion of form data such as an email address, name, or city name may be autocompleted as the user types.
  • Load on demand: Based on a client event, an HTML page can fetch more data in the background, allowing the browser to load pages more quickly.
  • Sophisticated user interface controls and effects: Controls such as trees, menus, data tables, rich text editors, calendars, and progress bars allow for better user interaction and interaction with HTML pages, generally without requiring the user to reload the page.
  • Refreshing data and server push: HTML pages may poll data from a server for up-to-date data such as scores, stock quotes, weather, or application-specific data. A client may use Ajax techniques to get a set of current data without reloading a full page. Polling is not the most effecient means of ensuring that data on a page is the most current. Emerging techniques such as Comet are being developed to provide true server-side push over HTTP by keeping a persistent connection between the client and server. See this blog entry on Comet using Grizzly for more on the development of server push with Java technology.
  • Pa

    剩余内容已隐藏,支付完成后下载完整资料


    异步JavaScript技术和XML ( AJAX )与Java平台

    Greg Murray,2005年6月9日发表;2006十月更新

    文章来源:http://java.sun.com/developer/technicalArticles

    使用过Flickr、GMail,、Google、Suggest或Google地图的人都知道一种全新的动态WEB应用正在成型。这些应用看上去和传统桌面应用非常相似,他们不依赖于插件或者浏览器特效。传统意义上的WEB应用就是一组网页,当页面上有任何一点内容有所变化的时候必须更新整个网页。一些技术比如JavaScript和CSS已经非常成熟,你可以使用它们进行高效地创建动态网页,并可以在大多数主流浏览器上运行。本文将细述数种可以使你的WEB应用更丰富更具交互性(就象桌面应用一样)的技术。

    利用JavaScript技术,HTML网页可以异步调用生成服务器上的服务并且获取返回的XML文档的结果,然后JavaScript再使用这个XML文档更新或改动本网页的文档对象模型(DOM)。AJAX就是近年来出现用来描述这种交互模式的新名词。

    AJAX并不是新事物,数年前使用微软IE浏览器的开发者们就曾使用过它,直到最近,这项技术作为远程脚本而更出名了。以前WEB开发者使用插件,applets或者隐藏框架来仿效这种交互模式。但是现在,XMLHttpRequest对象技术已经在各大平台的主流浏览器上普及,所以这种模仿的情况越来越少了。真正神奇的事情在于JavaScript和XMLHttpRequest对象技术的结合,尽管XMLHttpRequest对象技术并不属于JavaScript标准规范,但是现代的主流浏览器都支持这个对象。Firefox、IE、 Safari这些浏览器对JavaScript和CSS的执行有微小不同,但这些不同之处很容易理解和处理。如果你一定要兼容老一代浏览器那还是不要用AJAX了。

    基于AJAX的客户端独特之处在于包含特定页面控制逻辑的客户端嵌入式JavaScript技术。页面与JavaScript的交互建立在事件的基础上(比如文档加载事件,鼠标点击事件,焦点变化事件,甚至一个时钟事件)。AJAX清楚的将表示逻辑和数据分离开来,一个HTML网页能够在需要的时候获取以比特为单位的数据片段,这不同于以前的有一点变化就必须刷新整个页面的做法。同时AJAX也需要一种完全不同的服务端架构来支持这种交互模式。以前的传统服务端WEB应用专注于为每一个客户端的每一次请求生成HTML页面,每一次客户端接到响应都要刷新和重新渲染整个页面。而我们所谈的WEB应用专注于客户端把HTML文档当作模版或容器,客户端向这个容器中插入内容,作到这些的原理就是每当客户端发生事件,客户端都可以向服务端发出请求并使用服务端返回的XML数据。

    一些AJAX的应用如下:

    实时的表单数据验证:像ID、序列号、邮政编码、优惠卷号码这样的表单数据可以在用户提交整个表单之前就得到验证。

    自动补全:一些特定表单数据比如email、姓名、城市名可以根据用户的类型自动填写。

    负荷需求:基于客户端的事件,一个HTML页面可以在后台获取更多的数据,让网页浏览器加载更快。

    智能客户端接口控制:诸如树,菜单,数据表,丰富的文本编辑器,日历和进度条允许用户更好地互动和交互HTML网页,一般而言不需要重新加载页面。

    更新数据和服务器推:HTML网页可能从一个服务器获得最新数据,如分数,股票报价,天气预报,或适用的具体数据。A client may use Ajax techniques to get a set of current data without reloading a full page.客户可以在不重新加载数据的情况下使用Ajax技术得到了一套最新数据。轮询轮询轮询轮询不是最有效的手段来确保数据在网页上是最新的。 Emerging techniques such as Comet are being developed to provide true server-side push over HTTP by keeping a persistent connection between the client and server.新兴技术,如彗星正在制定,提供真服务器端推HTTP以保持客户端和服务器之间的持久链接。See this blog entry on Comet using Grizzly for more on the development of server push with Java technology.看到这个博客条目对彗星使用灰熊更多的发展,推动服务器与Java技术。

    部分更新:一个HTML页面可以提交表单数据,而不需要一整页刷新。

    混搭:一个HTML页面可以通过使用服务器端的代理,或者由包括组合外部数据与您的应用程序或服务的资料来获取数据。For example, you can mix content or data from a third-party application such as Google Maps with your own application.例如,您可以混合第三方应用程序的内容或数据,例如谷歌地图与您自己的应用程序。

    网页作为一种应用:Ajax技术,可创造单一网页的应用程序,应用程序的外观和感觉很像一个桌面应用程序。See the article on the use of Ajax and portlets for more on how you can use portlet applications today.看到一篇关于使用Ajax和门户提供更多关于如何使用的portlet应用的。

    这些用处并不全,但是它们说明了AJAX交互使得WEB应用可以作到大量以前无法作到的事情。

    解剖一个AJAX交互:

    现在我们已经讨论了Ajax与一些较高级别的问题,我们把所有的问题放在一起,看一个基于AJAX的Java应用程序。

    Lets consider an example.我们考虑一个例子,A web application contains a static HTML page, or an HTML page generated in JSP technology contains an HTML form that requires server-side logic to validate form data without refreshing the page.一个web应用包含一个静态网页,或HTML页面中生成的JSP技术包含HTML表单,需要服务器端的逻辑来验证表单数据而无需刷新页面。 A server-side web component (

您需要先支付 30元 才能查看全部内容!立即支付

课题毕业论文、开题报告、任务书、外文翻译、程序设计、图纸设计等资料可联系客服协助查找。