Java中如何转义HTML符号呢?
下文笔者讲述Java代码将html转义的方法及示例分享,如下所示
使用 Apache Commons Lang 中的 StringEscapeUtils方法即可对html字符进行转移例:转义HTML符号
import static org.apache.commons.lang.StringEscapeUtils.escapeHtml; // ... String source = "The less than sign (<) and ampersand (&) must be escaped before using them in HTML"; String escaped = escapeHtml(source); //version 3 import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4; // ... String escaped = escapeHtml4(source);
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。