Chapter 4. Using Ajax

Asynchronous JavaScript and XML (AJAX or Ajax) is a technique for transferring data between a browser and a server asynchronously. "Asynchronously" implies that the web page continues to be processed while the request is sent from the browser to the server and a response is received. Ajax is based on JavaScript, Document Object Model (DOM), and XMLHttpRequest. Ajax provides dynamic interaction between a browser and a server and can be used in several types of applications, such as for validating a form that requires a unique identifier without submitting the form, autocompleting input fields based on partial input, and refreshing information on a web page periodically without having to reload the web page, thus incurring less bandwidth usage.

In this chapter, we will create an Ajax application in the Eclipse IDE, compile and package the application using Maven, and run the web application on WildFly 8.1 with MySQL database. In this chapter, we will cover the following topics:

  • Setting up the environment
  • Creating a Java EE web project
  • Creating a user interface
  • Creating a servlet
  • Deploying the Ajax application with Maven
  • Running the Ajax application

Setting up the environment

We need to install the following software:

Set the JAVA_HOME, JBOSS_HOME, MAVEN_HOME, and MYSQL_HOME environment variables. Add %JAVA_HOME%/bin, %MAVEN_HOME%/bin, %JBOSS_HOME%/bin, and %MYSQL_HOME%/bin to the PATH environment variable.

Create a WildFly 8.1.0 runtime as discussed in Chapter 1, Getting Started with EJB 3.x.

Create a MySQL database CATALOG with the following SQL script:CREATE TABLE Catalog(CatalogId VARCHAR(255), Journal VARCHAR(255), Publisher Varchar(255), Edition VARCHAR(255), Title Varchar(255), Author Varchar(255));

INSERT INTO Catalog VALUES('catalog1', 'Oracle Magazine',  'Oracle Publishing', 'September-October 2010', 'Using Oracle Essbase Release 11.1.2 Aggregate Storage Option Databases', 'Mark Rittman and VenkatakrishnanJanakiraman'),

INSERT INTO Catalog VALUES('catalog2', 'Oracle Magazine',   'Oracle Publishing', 'July-August 2010', 'Infrastructure Software and Virtualization', 'David Baum'),

We will use the same MySQL data source we used in earlier chapters. The procedure to create a MySQL module, define a MySQL driver, and configure a data source is discussed in Chapter 1, Getting Started with EJB 3.x.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.110.91