1

I am trying to add a hyperlink in java file.

TestHyperlink.java

class TestHyperlink.java {
  String url = "stackoverflow.com/questions/ask";
  String someVariable = "testUrl";
  Html entryLink = new Html("<a target=\"_blank\" href=url>someVariable</a>");
}

I am trying to use two string variables url and someVariable but I am not sure how to do it. My hyper link appears as 'someVariable' and on click leads to a broken page.

What I seek is a hyperlink which appears as testUrl and on click leads to a desired url page, stackoverflow.com/questions/ask in this case.

Thanks, Sony

1 Answer 1

2

Java doesn't interpolate variables inside Strings. You need to change to new Html("<a target=\"_blank\" href=\"" + url + "\">" + someVariable + "</a>");

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

1 Comment

This leads me to an about:blank page in chrome, also I want the link to appear as testUrl(value of a variable) not someVariable(not a fixed value)

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.