简体   繁体   中英

How to import/call methods/class from Java into Javascript code

Probably this is is a very basic question. Apologies for that. I have been trying at various ends to find an answer for this.

My question is like this:

I have a java code relating to reading an inbox. I need to call this code/method/class in the new javascript file, which I will be developing.

Basically, I need to use the methods in the java file onto the new javascript file

Can anyone please help?

There are certain options, as this questions is primarily opinion based, so here is my opinion.

  1. Using Ajax. You can call your back end methods through Ajax.

  2. Another option is using DWR, Direct Web Remoting, its a sort of ajax but made easy. The java methods are made to be used by javascript. Full example: https://www.javaworld.com/article/2071890/web-app-frameworks/ajax-made-simple-with-dwr.html

function updateResults() {
  DWRUtil.removeAllRows("apartmentsbody");

  var bedrooms = document.getElementById("bedrooms").value;
  var bathrooms = document.getElementById("bathrooms").value;
  var price = document.getElementById("price").value;

  ApartmentDAO.findApartments(fillTable, bedrooms, bathrooms, price);

  $("resultTable").style.display = '';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM