0

Hello i want to acess data from my mysql server in javascript. But i have no clue how to do so. I am running tomcat so it is not handy to use php. Can someone please help me !

I thought maybe there is some way to get the variables from my servlet, but it seems not possible to get javascript connected to java or is there ?

var blueDates = magic way to get data from my mysql server;

Greetings, Rick

2
  • 3
    JavaScript is (mostly) a client-side language. You'll need to communicate to the server that's hosting your database, and use some sort of server-side language to actually query the database. Commented Feb 9, 2015 at 10:11
  • "but it seems not possible to get javascript connected to java" What do you mean exactly by that? Perhaps you are running into CORS restrictions? en.wikipedia.org/wiki/Cross-origin_resource_sharing Commented Feb 9, 2015 at 12:49

1 Answer 1

2

You have to implement a servlet that returns the data from mysql. A good way to do so is to implemente a servlet that returns a JSON object containing the mysql data.

Once this is done use AJAX to ask the servlet for the data.

There is a lot of information about implementing this. After all this is a minimal REST implementation for a GET request. Just ask Stackoverflow or Google.

Sign up to request clarification or add additional context in comments.

1 Comment

I already made a servlet, and wrote the MySQL class. The connection works but i do not know how i can send this information to the java script class that needs to present this information in my jsp before the page loads up ( or the java script loads up ) I will the some of tha AJAX. Thanks for any reply btw !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.