Ajax application on tomcat

Can some body tell me how i can run this ajax application on tomcat server. I want to print Hello world in the html page on to tomcat server. Need a steps to do that in eclipse


My code is like this

in the data.txt i have Hello world

In the script.js file i have
var request;
if (window.XMLHttpRequest) {
      request = new XMLHttpRequest();
} else {
      request = new ActiveXObject("Microsoft.XMLHTTP");
request.open('GET', 'data.txt');
request.onreadystatechange = function() {
      if ((request.readyState===4) && (request.status===200)) {

In the  index.html i have
<!DOCTYPE html>
<html lang="en">
      <meta charset="utf-8" />
      <title>JavaScript AJAX</title>
<script src="script.js"></script>
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


  in eclipse just go to File->New  menu and create one dynamic web project.

  after that go to WebContent folder and create one folder named js after that create two file under js folder named data.txt and script.js and copy paste your code just over there.

 create one file index.html under webContent folder and copy paste your code of index.html over there just change one thing in that code as per below

 change <script src="script.js"></script> to <script src="js/script.js"></script>

now run your project by right click on project folder and run as --> run as server

roy_sanudeveloperAuthor Commented:
Hi Hiren,

I followed the steps

but it is not loading that script.js file.  what is the reason ? it is showing blank


 which browser u use to run this project if u use google-chrome then just right click on page and select inspect element option in that select console option and after that refresh your page u found any single error over there console part?
roy_sanudeveloperAuthor Commented:
it shows the console error as
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/AjaxExamples/data.txt

  As per your Error u must have to put your data.txt file in the folder where script.js file is located.

 I attached some screen-short of my project and your project structure something like that.

Check proper location on the left side of eclipse and put file on proper location.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.