1

I have two separate java and javascript file. I want to call a method which is in my java class from my javascript function. Can anyone help me please ?

4
  • So you would ned to make a call to the server. Commented Sep 15, 2016 at 20:33
  • I think more context is needed. Is this a Java function in an Applet? Are you talking about a GWT problem? Commented Sep 15, 2016 at 20:34
  • Like @epascarello implied an ajax call to a servlet would normally work. Commented Sep 15, 2016 at 20:35
  • A few thoughts... You could use ajax to call what I assume could be a jsp page. Another option, use React JS or Angular JS to connect server-side. Commented Sep 16, 2016 at 1:49

1 Answer 1

1

I'm not sure what the structure of your code looks like but you cannot call a java method directly from javascript. You would need to use something that can map your URL to the method you are calling. You would need to make a servlet or JSP and use an ajax call to communicate to the server and call your desired method.

The following tutorial should help you get started writing something like this:

https://netbeans.org/kb/docs/web/ajax-quickstart.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.