0

I have tried following java code snippet ....but it doesn't work.Also i want func() to be activated only after href url is executed. Kindly help me with it.Thanks :)

    stringBuilder.append("<a  href=\"https://google.com\" onclick=\"myfunc(){ <%= func() %> }\" >");
    stringBuilder.append("Click here</a>");

    public static void func() {
           System.out.println("Print something");}

2 Answers 2

0

I don't think I get your question right. But you may want to take a look at a similar question posted here. I am not exactly sure what you are trying to do.

Calling java class from javascript written in html

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

Comments

0

Html is rendred on the browser (client side) then you can't call java code from it ! Instead, you can call Javascript function that invoque a backend through http or ajax

2 Comments

Can u please elaborate it? I have used myfunc(), js func to invoke func(), java method.
This is examples how to use onclick events w3schools.com/js/js_htmldom_events.asp You need in the script part to write the function that call ajax or http in order to call a java servlet/ http endpoint

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.