Javatpoint Logo

91-9990449935

 0120-4256464

AJAX example with Database

In this example, we are interacting with the database. You don't have to make any extra effort. Only write the database logic in you server side page.

In this example, we have written the server side code inside the index.jsp file.

Steps to create ajax example with database through jsp

You need to follow following steps:

  1. load the org.json.jar file
  2. create input page to receive any text or number
  3. create server side page to process the request

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 page to receive any text or number

In this page, we have created a form that gets input from the user. When user press any key sendInfo() function is called. We have written all the ajax code inside this function.

We have called the getInfo() function whenever ready state changes. It writes the returned data in the web page dynamically by the help of innerHTML property.

table1.html

create server side page to process the request

In this jsp page, we printing the id and name of the employee for the given id.

index.jsp


Output

ajax example using database output ajax example using database output 2