How to import java packages into js file

I was wondering how to import my java packages into a js file, and then call the class methods on the created object.

The reason I need to import is the desire to get data from a connection to my database regarding dates, and I have a class that allows me to do this. So I need to import the package, then create a class object, and then call the methods on my object.

I would be grateful for your help, Thanks, John

+3
source share
6 answers

, , . Java Rhino 6. , , - , - , JavaScript , soapUI PTC Integrity - .

importPackage(java.io);

Wikipedia: Rhino ( JavaScript) .

+6

JSP Java javascript.

Java JSP, :

<%@page import="com.acme.MyClass"%>

JS, JSP:

<script type="text/javascript">
var f = function(param){
 console.log(param);
}

f('<%= MyClass.foo().toString() %>');
</script>

, ?

, .

+2

, - DWR. , , Java ( ) JavaScript ( ). DWR - , :)

+2

Java Java , , javascript ajax, javascript , http, ftp.

+1

. Java- . , JavaScript. , .

!

, . . , , , .

Also, in addition to this method and many other great suggestions, check out GWT. http://code.google.com/webtoolkit/overview.html

0
source

Calling java methods from javascript is not possible.

JSP file:

function doSomething {
   <% SomeClass.someMethod(); %>
}

<%!
class SomeClass {
  public static void someMethod() {
    // 
  }
}
%>

someMethod will not start when doSomething is called, but it will work when jsp generates a response.

-3
source

Source: https://habr.com/ru/post/1765974/


All Articles