You can't execute Java code from a Javascript function directly.
All you can do is have the Javascript generate an Http request to a servlet which can execute the Java code for you and optionally return something which your Javascript could then use to generate content for your page.
It is tricky, but it can be done. Can't tell you how we solved it as the code is not mine to give away.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337