Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
希望为我的GWT应用程序(Java 7)中的每个http/https超链接添加锚定html标记_Java_Javascript_Regex_Gwt_Java 7 - Fatal编程技术网

希望为我的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("<", "&lt;"); txt = txt.replaceAll(">", "&gt;"); txt = txt.replaceAll("\n", "");

在GWT应用程序(使用Java 7)中,我希望为字符串变量中的每个http/https链接添加锚html标记

它在嵌入模式下工作,但在生产中不工作

private String clearTextContent(String txt) {
    txt = txt.replaceAll("<", "&lt;");
    txt = txt.replaceAll(">", "&gt;");

    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,并非所有小部件都能做到这一点,因为>或 有几种方法可以生成安全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);