fj785
fj785

Reputation: 133

How do I integrate my Java code to a web application with standard HTML, CSS, Javascript?

sorry for the newbie question so please go easy on me. I am a bit new to Java but have web development experience working with a MERN stack to connect front end to back end.

Could anyone point me in the right direction to a tutorial I could reference to integrate Java into my web app as Google is of little help? Are you able to for example use Java methods inside of Javascript functions for event handlers?

Say I wanted to add a Java object to an arraylist when an onClick event triggers. Would I be able to call the Java method to add inside of the onClick event handler?

Upvotes: 3

Views: 362

Answers (1)

jordiburgos
jordiburgos

Reputation: 6302

No, you are not able to call a Java method from JavaScript directly.

One of the solutions would be to have a Java web server that listens to requests. Then from JavaScript (web client), make requests to the Java server to obtain the responses.

For Java server: simple Web server, simple REST service, Spring framework, Play framework, etc...

For JavaScript client: vanilla AJAX request, JQuery, other JS framworks, ...

Upvotes: 3

Related Questions