Your Javascript runs client side in the browser so will not normally interact with your Java code running server side. You might want to expose your Java method as a RESTful API endpoint and perform an AJAX call in the Javascript code.
- SEE: http://docs.jquery.com/Tutorials (ajax tutorial)
There are a few ways it's technically possible but unsure why you would want to do it that way:
- SEE: http://www.andonyar.com/rec/2008-12/gemse/demo/doc/dev/java.xhtml
- SEE: http://www.rgagnon.com/javadetails/java-0170.html
Google's web toolkit:
- SEE: http://code.google.com/p/google-web-toolkit-doc-1-5/wiki/DevGuideRPCDeployment