Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

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 (MongoDB, Express, Angular, Node) 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?

like image 988
fj785 Avatar asked Oct 28 '25 02:10

fj785


1 Answers

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, Jakarta Servlet, REST service, Spring framework, Play framework, etc...
  • For JavaScript client: vanilla AJAX request, JQuery, other JS framworks, ...
like image 198
jordiburgos Avatar answered Oct 30 '25 17:10

jordiburgos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!