使用Java标准库将HTML字符转换回文本 [英] Convert HTML Character Back to Text Using Java Standard Library
本文介绍了使用Java标准库将HTML字符转换回文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用Java Standard Library将一些HTML字符转换回文本。我想知道是否有任何库会达到我的目的吗?
I would like to convert some HTML characters back to text using Java Standard Library. I was wondering whether any library would achieve my purpose?
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
// "Happy & Sad" in HTML form.
String s = "Happy & Sad";
System.out.println(s);
try {
// Change to "Happy & Sad". DOESN'T WORK!
s = java.net.URLDecoder.decode(s, "UTF-8");
System.out.println(s);
} catch (UnsupportedEncodingException ex) {
}
}
推荐答案
我认为雅加达共享Lang图书馆的StringEscapeUtils.escapeHtml()和unescapeHtml()方法是你正在寻找的。请参阅 http:// commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/StringEscapeUtils.html 。
I think the Jakarta Commons Lang library's StringEscapeUtils.escapeHtml() and unescapeHtml() methods are what you are looking for. See http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/StringEscapeUtils.html .
这篇关于使用Java标准库将HTML字符转换回文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文