Java development for the Ajax: Construction of dynamic Java applications
Level: Intermediate
Philip McCarthy (philmccarthy@gmail.com), the software development consultants, independent consultants
October 20, 2005
In Web application development, pages duty-cycle is one of the biggest obstacles to the use for Java? Developers, is a tough challenge. In this series, the writer Philip McCarthy presents a dynamic application experience to create a ground-breaking way. Ajax (Asynchronous JavaScript and XML) is a programming technology, which allows for Java-based Web applications to Java technology, XML and JavaScript portfolio, thus breaking the pages Heavy paradigm.
Ajax (Asynchronous JavaScript and XML) is a Web application development tool that uses client-side script and the Web server data exchange. Therefore, the interruption will not use interactive refresh complete pages, we can dynamically update Web pages. Using Ajax, you can create richer, and more dynamic Web application user interface, and its immediate availability even close to the machine desktop applications.
Ajax is not a technology, and more like a model model - an identification and description of the design of useful technology. Ajax is new, because many developers have just begun to know about it, but all realize Ajax application components are already in existence a number of years. At present, it is because of attention in 2004 and 2005 there have been some great technology based on Ajax dynamic Web UI, is the most famous of GMail and Google Maps applications, as well as photo-sharing site Flickr. These user interface is sufficiently innovative, some developers call "Web 2.0", therefore there is interest in Ajax applications rapid rise.
In this series, I will provide the use of Ajax application development tool for the needs of all. In the first article, I will explain the concept behind Ajax, for the demonstration of Java-based Web applications Ajax interface created the basic steps. I will use code examples to demonstrate Ajax applications such dynamic server-side Java code and client JavaScript. Finally, I would point out that some of the inadequacies Ajax way, as well as in the creation of Ajax applications should be taken into account some of the wider availability and access issues.
list). 3, as shown in the list, addToCart () needs to be done is the first thing by calling the newXMLHttpRequest list 2 () function to XMLHttpRequest object. Next, it registered a callback function to receive the server response (I explained in detail later this step; please refer to the list 6).
Because the request would amend the state on the server, so I will do this with HTTP POST work. POST data requests sent through three steps. First, the need to open communication with the server resources POST connection - In this example, a server resources are mapped to the URL cart.do servlet. Then, I set up an XMLHttpRequest, pointing request form is the content of the coded data. Finally, I used as a form of data encoded request sent in the request.
List three of these steps on them.
downloaded from) the Cart.java, we can see that the XML generated only way to add strings together. Although this example is sufficient, but for the Java code generation, XML is the worst way. I will be in the next period of this series introduced some better way.
Now that you know the CartServlet response XMLHttpRequest way. One thing is the return of the client to see how to update pages with XML response state.
![]()
![]()
![]()
3 in the list have already seen how to call getReadyStateHandler () function to create event handler function. Then this incident handling functions allocated to onreadystatechange property. GetReadyStateHandler () use of such a fact: the JavaScript function is a target. This means that other functions can function parameters can also create and return other functions. GetReadyStateHandler () function is to return a check XMLHttpRequest have been completed and passed to the XML response to the events specified call handling functions. Inventory is getReadyStateHandler () code.
3 in the list saw getReadyStateHandler () is called like this: handlerFunction = getReadyStateHandler (req, updateCart). In this example, getReadyStateHandler () function will return the check req variables in the XMLHttpRequest have been completed, and then use the XML response to the call entitled updateCart function.
list 1), reflect the new shopping cart contents. The focus here is used to extract data from the XML DOM calls. Cart element attributes in the generated sequence Cart generate XML into a timestamp, check it can guarantee that the new data will not be Cart old data coverage. Ajax is asynchronous nature of the request, so the server can handle inspection in order not respond at the situation.
download a). This example is very simple, there are many needs improvement. For example, I include a shopping cart removal from the project server-side code, but not from the UI to access it. As a good practice, try in the application of existing JavaScript code on the construction of this function can be realized from the code.
![]()
![]()
![]()
reference, Ajax was specifically address the issue of application availability article.
list 7). This is a very basic approach can be used to Cart scene, but may not be suitable for other scenes. So in the design requested to consider how to deal with asynchronous server response.
![]()
![]()
![]()
reference a reference listed in the article, especially if you are a client or Gangchachu Ajax development of the case. You should also spend some time on the source code examples and consider strengthening its approach.
In this series the next article, I will discuss in depth XMLHttpRequest API, and recommend some from JavaBean easily create XML approach. I will also introduce alternative to Ajax XML data transmission, such as JSON (JavaScript Object Notation) lightweight data exchange format.
![]()
![]()
![]()
HTTP ![]()
Information on the download ![]()
original English text.
Access to products and technologies
- Mozilla Firefox: DOM Inspector and JavaScript Debugger expansion eliminate many Ajax development of the pain.
Discuss
- Participate in the discussion forum.
- DeveloperWorks blogs: Add developerWorks community.
philmccarthy@gmail.com e-mail contact with him.
Tags: java date, java extend, java import, java io, java package, java parseInt, java rmi, java sql, java toString, java util






