Ajax Java Example
To create ajax example, you need to use any server-side language e.g. Servlet, JSP, PHP, ASP.Net etc. Here we are using JSP for generating the server-side code.
In this example, we are simply printing the table of the given number.
Steps to create ajax example with jsp
You need to follow following steps:
- load the org.json.jar file
- create input page to receive any text or number
- create server side page to process the request
- provide entry in web.xml file
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 clicks on the showTable button, 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 table of given number.
index.jsp
web.xml
Output