希望为我的GWT应用程序(Java 7)中的每个http/https超链接添加锚定html标记
在GWT应用程序(使用Java 7)中,我希望为字符串变量中的每个http/https链接添加锚html标记 它在嵌入模式下工作,但在生产中不工作希望为我的GWT应用程序(Java 7)中的每个http/https超链接添加锚定html标记,java,javascript,regex,gwt,java-7,Java,Javascript,Regex,Gwt,Java 7,在GWT应用程序(使用Java 7)中,我希望为字符串变量中的每个http/https链接添加锚html标记 它在嵌入模式下工作,但在生产中不工作 private String clearTextContent(String txt) { txt = txt.replaceAll("<", "<"); txt = txt.replaceAll(">", ">"); txt = txt.replaceAll("\n", "");
private String clearTextContent(String txt) {
txt = txt.replaceAll("<", "<");
txt = txt.replaceAll(">", ">");
txt = txt.replaceAll("\n", "");
txt = txt.replaceAll("\\|", "<br/>");
// Display Link for URLs
txt = txt.replaceAll("(\\A|\\s)((http|https|ftp|mailto):\\S+)(\\s|\\z)", "$1<a target='_blank' href='$2'>$2</a>$4");
}
输出:
Hello|<a target='_blank' href='http:///www.google.com'>http:///www.google.com</a>|... That's it!
你好| |。。。就这样!
我已经读到,在嵌入模式下,GWT使用javascript正则表达式,在生产中使用java正则表达式
你有什么建议来解决我的问题吗
谢谢 如果您想在小部件中嵌入HTML,并非所有小部件都能做到这一点,因为>或
SafeHtml safeHtml = SafeHtmlUtils.fromString(myCodeAsString);
htmlBlock.setHtml(safeHtml);
因此,请检查显示字符串变量的小部件的类型,并在必要时切换到另一个小部件
Hello|<a target='_blank' href='http:///www.google.com'>http:///www.google.com</a>|... That's it!
SafeHtml safeHtml = SafeHtmlUtils.fromString(myCodeAsString);
htmlBlock.setHtml(safeHtml);