Escolar Documentos
Profissional Documentos
Cultura Documentos
1 sur 5
http://www.regdeveloper.co.uk/2006/06/09/ajax_web_tutorial/print.html
How often have you found yourself filling out a web form requiring umpteen fields to be
specified which, when you submit the form, returns the message, Invalid input or Field
value not valid?
Asynchronous JavaScript And XML (AJAX) provides a method for the completion and
validation of web forms. Its a web technique for developing asynchronous web
applications using JavaScript, Document Object Mode (DOM) and XMLHttpRequest
technologies. AJAX provides dynamic interaction between a client and a server and has
various applications, such as:
Dynamic Form Data Validation. As a user fills out a form that requires a unique
identifier in a field, the form data is validated without the form being submitted.
Auto-completion. As a user adds some data to a form, the remaining form gets
auto-completed.
Refreshing data on a page. Some web pages require that data be refreshed
frequently, a weather web site for example. Using the AJAX technique, a web page
may poll the server for latest data and refresh the web page without reloading the
page.
JavaScript and XML DOM technologies are relatively established technologies so we
wont discuss them further here. XMLHttpRequest, however, is a relatively new technology
and merits discussion.
Overview of XMLHttpRequest
The XMLHttpRequest object provides asynchronous communication between web
applications and underlying servers and business services. Using the object, clients may
submit XML data to, and retrieve it from, a web server without reloading the page. XML
data may be converted to HTML on the client side, using DOM and Extensible Style sheet
Transformations (XSLT).
SPONSORED LINKS
Browse The Register's IT training library
At Rackpace Managed Hosting we're
passionate about the hosting business and
we're here to stay - Click Here
Search the latest IT jobs - Jobsite
29/06/2006 11:58
2 sur 5
http://www.regdeveloper.co.uk/2006/06/09/ajax_web_tutorial/print.html
Description
Cancels the current HTTP request.
Gets all the response headers. readyState is required to
be 3 or 4 to retrieve the response headers.
Gets a specified response header. readyState is required
to be 3 or 4 to retrieve a response header.
29/06/2006 11:58
3 sur 5
http://www.regdeveloper.co.uk/2006/06/09/ajax_web_tutorial/print.html
open(string method, string url, Opens a HTTP request. Does not send a request.
boolean asynch, string
readyState property gets set to 1. responseText,
username, string password)
responseXML, status, and statusText properties get reset
to their initial values. The HTTP method and server URL,
which may be relative or absolute, are required
parameters. Boolean parameter asynch specifies if HTTP
request is asynchronous. Default value is true. Username
and password are optional.
<send(data)
Sends a HTTP request to the server, including data,
which may be a string, an array of unsigned bytes, an
XML DOM object, or null. The send() method is
synchronous or asynchronous corresponding to the value
of the asynch argument in the open() method. If
synchronous, the method does not return until the
request is completely loaded and the entire response has
been received. If asynchronous, method returns
immediately. The readyState property gets set to 2 after
invoking the send() method. The readyState property
gets set to 4 after the request has completed loading.
Sets HTTP request headers.
setRequestHeader(string
headerName, string
headerValue)
Installing Software
AJAX being a web technique, not a technology, does not in itself require any additional
software other than a browser that supports the XMLHttpRequest object. If not already
installed, we need to install a web browser, such as Internet Explorer (IE) 7
(http://www.microsoft.com/windows/ie/default.mspx), or IE 6
(http://www.microsoft.com/windows/ie/ie6/downloads/critical/ie6sp1/default.mspx), or Netscape 6+
(http://browser.netscape.com/ns8/).
To develop an AJAX web application, however, we need a web/application server.
Therefore, we download and install JBoss 4.0.2 (http://www.jboss.com/downloads/index). We
also need to install the J2EE 1.4 SDK (http://java.sun.com/j2ee/1.4/index.jsp). We then need to
copy the lib/j2ee.jar JAR file from the J2EE 1.4 installation to the server/default/lib
directory of the JBoss installation.
The AJAX application that we will develop retrieves data from a database. So, we need to
install a relational database such as the open source database MySQL 5.0 (from here
(http://www.mysql.com/products/database/mysql/community_edition.html)), which is used for this
article. Finally, well need the MySQL JDBC driver Connector/J
(http://www.mysql.com/products/connector/j/).
A new user may be added to the user table with an GRANT statement as shown below (as
an example, were creating a user 'mysql' with password 'mysql'):
GRANT ALL PRIVILEGES ON test TO 'mysql'@'localhost'
29/06/2006 11:58
4 sur 5
http://www.regdeveloper.co.uk/2006/06/09/ajax_web_tutorial/print.html
We also need to create an example table in the MySQL database. To create a table, login
to the database as mysql user and run the SQL script catalog.sql from the Resources zip
file here (http://regmedia.co.uk/2006/06/09/ajax_resources.zip).
Next we configure the JBoss application server with the MySQL database. To do this, we
first need to copy the MySQL driver classes into the classpath.
Copy the JAR file mysql-connector-java-3.1.11-bin.jar to the
<jboss-4.0.2>/server/default/lib directory. <jboss-4.0.2> is the directory in which JBoss
4.02 is installed.
To use the MySQL data source, copy <jboss-4.0.2>/docs/examples/jca/mysql-ds.xml to
the <jboss-4.0.2>/server/default/deploy directory.
Modify the mysql-ds.xml configuration file by setting <driver-class/>to
com.mysql.jdbc.Driver and <connection-url/> to jdbc:mysql://localhost:3306/test.
In mysql-ds.xml also specify user-name as mysql and password as mysql. The jndi-name
is set to MySqlDS by default. The mysql-ds.xml file is available in the Resources zip file
here (http://regmedia.co.uk/2006/06/09/ajax_resources.zip).
We also need to modify the <jboss-4.0.2>/server/default/conf/login-config.xml with MySQL
database settings. Add the <application-policy/> element in resource file login-config.xml
to login-config.xml.
Once the mysql-ds.xml and login-config.xml files have been modified, the JBoss 4 server
is configured for use with a MySQL database.
29/06/2006 11:58
5 sur 5
http://www.regdeveloper.co.uk/2006/06/09/ajax_web_tutorial/print.html
project. Next, select targets in the Ant build.xml file that will run to compile and deploy the
AJAX web application. Right-click on the build.xml file and select Run As and select the
second Ant Build selection. Select the Targets frame in the build.xml frame. Select the
checkboxes for the init, compile, and webapp targets and click on the Apply button.
Next, we will run the Ant build.xml file to compile our AJAX web application and deploy it
to the JBoss application server. Right-click on build.xml in the Package Explorer and
select Run As and the first Ant build.xml selection. The Ant build.xml script runs and
compiles; and then compiles and deploys the AJAX web application to the JBoss
application server.
We will discuss the detail of the AJAX web application in the next article in this series.
Related stories
Googled by GWT - Part 2 (29 June 2006)
http://www.regdeveloper.co.uk/2006/06/29/google_gwt-part2/
Googled by GWT - Part 1 (26 June 2006)
http://www.regdeveloper.co.uk/2006/06/26/google_gwt/
Introduction to Developing Web Applications with AJAX - Part 2 (20 June 2006)
http://www.regdeveloper.co.uk/2006/06/20/ajax_web_tutorial_part2/
IBM a go-go to the Ajax Dojo (6 June 2006)
http://www.regdeveloper.co.uk/2006/06/06/ibm_ajax_donation/
Adobe gets Spry about AJAX (14 May 2006)
http://www.regdeveloper.co.uk/2006/05/14/spry_ajax/
Nokia examining AJAX (19 April 2006)
http://www.regdeveloper.co.uk/2006/04/19/nokia_ajax/
A GI called Ajax (13 February 2006)
http://www.regdeveloper.co.uk/2006/02/13/tibco_ajax/
Ajax In Action (12 December 2005)
http://www.regdeveloper.co.uk/2005/12/12/ajax_in_action_book_review/
Copyright 2006
29/06/2006 11:58