-1

My group has a project that is upposed to connect a web page to a databse. the webpage is written in html, css, and javascript, and the database is written in mysql. we know there are issues with accessing databases from javascript, so we built a driver class from java that is supposed to control communication between the two.

the problem is that we do not know how to connect javascript with java during runtime. the way it is built, the javascript simply needs to call a java function and get the results. is there any simple way to do this? perhaps a certain library? we have little to no knowledge of other similar tools (i.e. jsp, xml) and would like to stick to the languages listed above.

MG115
  • 23
  • 4
  • Use [**AJAX**](https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX) to post your JavaScript data to a server-side page. – Obsidian Age Mar 18 '18 at 23:23
  • This is the subject of webapps, [spring framework](http://spring.io/) for example. Also [Spark Java](http://sparkjava.com/) – Victor M Perez Mar 18 '18 at 23:23
  • Perhaps the AJAX is what you need. – Ali Sheikhpour Mar 18 '18 at 23:23
  • If you need to have Java in the stack, have a look at a Java EE tutorial such as [this one](https://netbeans.org/kb/docs/javaee/javaee-gettingstarted.html). If not, you could e.g. [use Node.js to connect to the DB](https://hackernoon.com/setting-up-node-js-with-a-database-part-1-3f2461bdd77f). – Mick Mnemonic Mar 18 '18 at 23:35

2 Answers2

0

You can create a Java HTTP JSON server and then make a call to it from Javascript by using AJAX calls.

See here: Java simple HTTP JSON server

BJovke
  • 1,737
  • 15
  • 18
0

In order to provide easy access to java code(including static/dynamic web content) over HTTP interface you've to use one of the (servlet) containers - jetty, tomcat, spring-boot, etc.

In my opinion, since you've minimal experience developing/deploying java web applications jetty might be good option as it have good documentation to get started. Spring Boot is popular choice for Enterprise web development using Java - it might be more than you want to chew for the moment.

The Servlet(web) and JDBC(database) APIs what you will end up using on Java side.

VinPro
  • 882
  • 1
  • 6
  • 10