XMLHttpRequest with Struts Example Webapp

Home Page

Welcome! This webapp, which is attached to the article "Ajax using XMLHttpRequest and Struts" by Frank W. Zammetti, demonstrates a number of different usages of the XMLHttpRequest object in the Ajax model.

All of these examples have been tested in IE 6.0 and Firefox 1.0. They SHOULD work in any version subsequent to those, as well as Mozilla 1.0 and higher, Netscape 7 and higher, Safari 1.2 and higher and Opera 7.60 and higher.

Click the link of the example you would like to see:

Example 1. Simple URL retrieval and display.
This example allows the user to enter a URL, which is then retrieved and displayed in a <span>. This demonstrates that what is retrieved is NOT treated as an HTML document but rather a simple stream of data, hence the document is not parsed and page events don't fire, images don't get retrieved, etc. This example does NOT really use Struts, everything needed is in example1.htm.

Example 2. Dynamic table.
This example shows how a table can be built and displayed on-the-fly by showing sorting of a table based on clicks on the table headers.

Example 3. Dynamic <select> elements.
This example shows how the contents of a <select> can be changed on-the-fly in response to the change in another.

Example 4. Dynamic <textarea>
This example shows how a <textarea> can be loaded on-the-fly with content. Here is is one of three poems loaded based on a change in a group of radio buttons. Also note that unlike example 2 and 3 which renders the response directly in the Action, this one actually forwards to a JSP that is the response, and hence no Action is involved.

Example 5. Data submission.
This example shows how XMLHttpRequest can be used to submit data. In this example, a series of user inputs are used to create a simple CSV string, which is then submitted to an Action, the values placed in a Value Object, and that object passed back to the view for display.

Example 6. RSS example.
This example is a more real-world example. It retrieves an RSS feed from one of three user-selected sources, parses the feed and displays the headlines in clickable form. This demonstrates retrieving XML from a server and dealing with it on the client.

Example 7. RSS example #2.
This version of the RSS feed example allows you to enter the URL of an actual RSS feed. Otherwise it works the same as the other example. This one uses an Action to retrieve the XML, therebye getting around the cross-domain issues of the other example.