Reputation: 1587
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
Upvotes: 1
Views: 11280
Reputation: 27886
Java doesn't interpolate variables inside Strings. You need to change to new Html("<a target=\"_blank\" href=\"" + url + "\">" + someVariable + "</a>");
Upvotes: 2