trainingtrains Logo

91-9990449935

 0120-4256464

Search Example using AJAX in Java

In this example, we are creating a form to search employee by name using ajax in java. Here, we have written the two-tier application code, to make the application easy to understand. You can write the database code, according to your standard.

Steps to create search example using AJAX in Java

You need to follow following steps:

  1. Create table in database
  2. load the org.json.jar file
  3. Create input form
  4. Create server side page to search employee using name

Create table in database

In this example, we are using oracle 10g database. Here, we have created a table "emp911" which has following data.

search ajax table

Load the org.json.jar file

download this example, we have included the org.json.jar file inside the WEB-INF/lib directory.


Create input form

In this page, we have created a form that gets input from the user to search employee by name. When user releases the key after pressing through keyboard, searchInfo() function is called. The ajax code is written inside searchInfo() function.

index.html

Create server side page to process the request

In this jsp page, we are writing the database code to search employee starting with given name.

index.jsp


Output

See the search form.

ajax search example output 1

Now enter employee name. If employee name is not found, it will display "No record found!" message.

ajax search example output 2

Now enter employee name that exists in the table. Now it will display all records starting with given name.

ajax search example output 3