计算机专业毕业设计外文资料翻译--异步javascript技术和xmlajax与java平台(编辑修改稿)内容摘要:

gy. 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 bitesize pieces to be displayed. Ajax will require a different serverside architecture to support this interaction model. Traditionally, serverside 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 rerender the plete 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 serverside ponent. Some uses for Ajax interactions are the following: Realtime form data validation: Form data such as user IDs, serial numbers, postal codes, or even special coupon codes that require serverside validation can be validated in a form before the user submits a form. See Realtime Form Validation for details. Autopletion: A specific portion of form data such as an address, name, or city name may be autopleted 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 uptodate data such as scores, stock quotes, weather, or applicationspecific 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 serverside 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. Partial submit: An HTML page can submit form data as needed without requiring a full page refresh. Mashups: An HTML page can obtain data using a serverside proxy or by including an external script to mix external data with your application39。 s or your service39。 s data. For example, you can mix content or data from a thirdparty application such as Google Maps with your own application. Page as an application: Ajax techniques can be made to create singlepage applications that look and feel much like a desktop application. See the article on the use of Ajax and portlets for more on how you can use portlet applications today. Though not allinclusive, this list shows that Ajax interactions allow web applications to do much more than they have done in the past. The Anatomy of an Ajax Interaction Now that we have discussed what Ajax is and what some higherlevel issues are, let39。 s put all the pieces together and look at an Ajaxenabled Java application. Let39。 s 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 serverside logic to validate form data without refreshing the page. A serverside web ponent (servlet) named ValidateServlet will provide the validation logic. Figure 1 describes the details of the Ajax interaction that will provide the validation logic. Figure 1: An Ajax Interaction Provides Validation Logic The following items represent the setups of an Ajax interaction as they appear in Figure 1. 1. A client event occurs. 2. An XMLHttpRequest object is created and configured. 3. The XMLHttpRequest object makes a call. 4. The request is processed by the ValidateServlet. 5. The ValidateServlet returns an XML document containing the result. 6. The XMLHttpRequest object calls the callback() function and processes the result. 7. The HTML DOM is updated. Now let39。 s look at each step of the Ajax interaction in more detail. 1. A client event occurs. JavaScript technology functions are called as the result of an event. In this case, the function validate() may be mapped to a onkeyup event on a link or form ponent. input type=text size=20 id=userid name=id onkeyup=validate()。 This form element will call the validate() function each time the user presses a key in the form field. 2. A XMLHttpRequest object is created and configured. An XMLHttpRequest object is created and configured. var req。 function validate() { var idField = (userid)。 var url = validate?id= + encodeURIComponent()。 if (typeof XMLHttpRequest != undefined) { req = new XMLHttpRequest()。 } else if () { req = new ActiveXObject()。 } (GET, url, true)。 = callback。 (null)。 } The validate() function creates an XMLHttpRequest object and calls the open function on the object. The open function requires three arguments: the HTTP method, which is GET or POST。 the URL of the serverside ponent that the object will interact with。 and a boolean indicating whether or not the call will be made asynchronously. The API is (String method, String URL, boolean asynchronous). If an interaction is set as asynchronous (true) a callback function must be specified. The callback function for this interaction is set with the statement = callback。 . See section 6 for more details. 3. The XMLHttpRequest object makes a call. When the sta。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。