How can we fetch data in ajax through servlet?

View Answers

January 12, 2012 at 3:06 PM



<title>Ajax Example</title>

<script language="Javascript">

function postRequest(strURL) {

var xmlHttp;

if (window.XMLHttpRequest) { // Mozilla, Safari, ...

var xmlHttp = new XMLHttpRequest();

} else if (window.ActiveXObject) { // IE

var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");


xmlHttp.open('GET', strURL, true);

xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

xmlHttp.onreadystatechange = function() {

if (xmlHttp.readyState == 4) {






function updatepage(str){

document.getElementById("result").innerHTML =

"<font color='red' size='5'>" + str + "</font>";;


function showCurrentTime(){

var rnd = Math.random();

var url="showTime";






<h1 align="center"><font color="#000080">Ajax Example</font></h1>

<p><font color="#000080">&nbsp;This very simple Ajax Example retrieves the

current date and time from server and shows on the form. To view the current

date and time click on the following button.</font></p>

<form name="f1">

<p align="center"><font color="#000080">&nbsp;<input value=" Show Time "

type="button" onclick='JavaScript:showCurrentTime()' name="showdate"></font></p>

<div id="result" align="center"></div>


<div id=result></div>




import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class MyServletAjax extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
Date date = new Date();
PrintWriter pw = response.getWriter();





Related Tutorials/Questions & Answers:
ajax  please describe the ajax
Ajax  How to learn AJAX
Ajax  Hi, What is Ajax? What is the use of Ajax? Thanks   Hi, Ajax is set of technologies used to develop dynamic web applications. In Ajax following technologies is used: a) JavaScript b) XML c) HTTP d) CSS Learn
Ajax  how to impliment ajax in registration table using jsp-servlet
Ajax  send the example to fetch the data from the server by using ajax in java. for ex:-if there are states which is used to display in frontend we use ajax. send it to me
ajax  how to connect ajax with mysql without using php,asp or any other scripting language. please answer soon
ajax  HI, In my application using ajax if i type a managername in the textbox it should display all the employees under the that manager... me reg this. thanks KK   Combobox box using Ajax in JSP   i
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
options. I want to do it using ajax. My table is CREATE TABLE HT<em>
ajax  I am facing following problem, I am using ajax to get the data continousely without refreshing. Here i have devided a web page into 3 parts(top,left and right) using table in jsp. On the left part i am displaying some
AJAX with
AJAX with       Ajax resources, in a digg style, allows the user to register and addd his/her own links Read full Description
Ajax Learner - Ajax
Ajax Learner  Hi, This is Ziaul,I am working as Java/j2ee Developer from last one year. i have to use Ajax for my current project.pls guide me how should i proceed to learn Ajax. Thanks and Regards Ziaul Hauqe Siddique 
ajax synchronisation
ajax synchronisation  how to stop ajax execution for some specific time
Ajax tutorials
Ajax tutorials  Hi, Why I should learn Ajax? What is the use of Ajax and which is the best tutorial to learn Ajax? Thanks
Ajax example
Ajax example   Hi, Where can I find Ajax example program? Thanks   Hi, Get it at: Ajax Tutorials First Ajax Example Ajax Login Example Thanks
What is Ajax?
What is Ajax?  Hi, What is Ajax and what is use of Ajax in web programming? Thanks   Hi, Ajax stands for AJAX stands for Asynchronous... JavaScript and other technologies such as CSS and XML. Read more at What is Ajax
Learn Ajax
Learn Ajax  Hi, Give good links to learn ajax. What is the correct url at roseindia.net to learn Ajax? Thanks   Hi, If you are beginner in Ajax start learning from the index of Ajax tutorial. Start learning Ajax
Ajax samples
Ajax samples  Hi, Tell me the urls of ajax samples. I am trying to find good Ajax samples for learning Ajax programming quickly. As I have to work on an Ajax project in next few days. Thanks   Hi, Please see Ajax
Ajax wiki
Ajax wiki  Hi, What is the url of wiki for Ajax tutorial. Thanks   Hi, Here is the link: Wikipedia Ajax url. Thanks
Ajax sample
Ajax sample  Hi, Where I can find the samples of Ajax program? Thanks   Hi, Please see Ajax Tutorials. Thanks
Ajax scripts
Ajax scripts  Hi, Tell me the names of Ajax Scripts that can be used for writing Ajax based applications? Thanks   Hi, Please see the Ajax Web Framework page. Thanks
Ajax training
Ajax training  Hi, I am looking for Ajax Training. From where I get training on Ajax? Thanks   Hi, Please visit Ajax Training url. Thanks
ajax example
Ajax Example Here is the list of few Ajax examples at RoseIndia.net. Ajax example Ajax example   Hi, Where can I find Ajax example program? Thanks   Hi, Get it at: Ajax Tutorials First Ajax
Ajax applications
Ajax applications  Hi, Where can I find Ajax applications? Thanks
Ajax json
Ajax json  Hi, How consume json file in ajax program? Thanks
Ajax grid
Ajax grid  Hi, How I can create ajax grid in my program? Thanks
Ajax tools
Ajax tools  Hi, What all ajax tools are available for programming? Thanks
Ajax frameworks
Ajax frameworks   Hi, What all ajax frameworks available these days for web application? Thanks   Hi, Link for list of Ajax Framework page. Thanks
Ajax database
Ajax database  Hi, How I can access the database using Ajax and then show the result. Thanks   Hi, Following url might help you: PHP Ajax and Database Thanks
ajax programming
Ajax Programming What is Ajax Programming? Asynchronous JavaScript and XML briefly known as Ajax is used to interchange the data with the server... is based on the HTML, Java Script, CSS, and XML. Why Ajax Programming? When you
Ajax books
Ajax books  Hi, Which is the best Ajax books? Thanks   Hi, Please see Ajax Books. If you are publisher of ajax books email the detail to [email protected] We will then publish the link of your books. Thanks
Ajax PHP
Ajax PHP  Hi, How I can use Ajax with PHP scripting language? Thanks   Hi, Please Getting Started with Ajax tutorial. In this tutorial... forgot to check PHP AJAX Dropdown tutorial. Thanks
Cakephp Ajax
Cakephp Ajax  Hi, How to use Cakephp and Ajax together? Thanks
Prototype Ajax
Prototype Ajax  Hi, What is Prototype Ajax? Thanks   Hi, Prototype is Java Script Ajax framework which is used in Ruby on Rails for adding Ajax support. The Prototype framework helps the developers in easily develop
Ajax technology
Ajax technology   Hi, Tell me about different types of Ajax technology. If possible also give me the links of all the Ajax technologies. Which ajax technology I should use in my project? Thanks
Ajax programming
Ajax programming  Hi, How I can start ajax programming easily? I want to learn all the concepts of Ajax technologies and master each and every concept. What should be my starting point for Ajax programming? Thanks   
Ajax demo
Ajax demo  Hi, I am new to Ajax and I want to see the running example of Ajax examples. Various types of Ajax demo application will help me in understanding the features and capabilities of Ajax frameworks. I want to know
Using Ajax
Using Ajax  Hi, How I can use Ajax in web programming? Tell me any example which using Ajax to call server side script? Thanks   Hi, Here are examples: PHP Ajax and Database First Ajax Example Getting Started
Ajax examples
Ajax examples  Hi, I am Java programmer and I have done programming in Java. Now I am learning ajax from scratch. Tell me the good examples of Ajax... of web web applications. You can easily learn Ajax. Learn Ajax and jQuery from
AJAX Magazine
AJAX Magazine       AJAX blog focusing on new AJAX developments. Read full Description
Ajax library
Ajax library  Hi, What is Ajax Library? List down the latest ajax libraries. Thanks   Hi, Ajax allows the developers to build Ajax based rich internet applications. Ajax libraries is the packaged components
ajax news
Ajax news Welcome! to the News letter archive Welcome! to the News... "  Ajax Resources ; Ajax Links AJAX links, code samples and news    ... Ajax
ajax redefining
AJAX-Redefining Web Applications            Web Scenario without AJAX Ajax: An Introduction AJAX stands for Asynchronous JavaScript And XML AJAX
What is Ajax?
What is Ajax?  What is Ajax? I have to learn Ajax to work on one project. Thanks   Ajax is combination of many technologies for making it possible to develop responsive web applications. The term Ajax stands
PHP with AJAX  I want to update records of table in database using AJAX PHP MySQL. How can this be done using AJAX.   Please visit the following links: http://www.roseindia.net/php/php-Ajax-DB.shtml http
Learning Ajax
Learning Ajax  Hi, I have experience in web web application development. But I am new in Ajax programming. How I can learn Ajax? Thanks   Hi, Please check the thread Learning Ajax. Thanks