public class HtmlUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
RE_HTML_MARK |
static String |
RE_SCRIPT |
| 构造器和说明 |
|---|
HtmlUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
cleanHtmlTag(String content)
清除所有HTML标签
|
static String |
encode(String text)
转义文本中的HTML字符为安全的字符,以下字符被转义:
' with ' (' doesn't work in HTML4)
" with "
& with &
< with <
> with >
|
static String |
filter(String htmlContent)
过滤HTML文本,防止XSS攻击
|
static String |
removeAllHtmlAttr(String content,
String... tagNames)
去除指定标签的所有属性
|
static String |
removeHtmlAttr(String content,
String... attrs)
去除HTML标签中的属性
|
static String |
removeHtmlTag(String content,
boolean withTagContent,
String... tagNames)
清除指定HTML标签
不区分大小写 |
static String |
removeHtmlTag(String content,
String... tagNames)
清除指定HTML标签和被标签包围的内容
不区分大小写 |
static String |
restoreEscaped(String htmlStr)
还原被转义的HTML特殊字符
|
static String |
unwrapHtmlTag(String content,
String... tagNames)
清除指定HTML标签,不包括内容
不区分大小写 |
public static String restoreEscaped(String htmlStr)
htmlStr - 包含转义符的HTML内容public static String encode(String text)
text - 被转义的文本public static String cleanHtmlTag(String content)
content - 文本public static String removeHtmlTag(String content, String... tagNames)
content - 文本tagNames - 要清除的标签public static String unwrapHtmlTag(String content, String... tagNames)
content - 文本tagNames - 要清除的标签public static String removeHtmlTag(String content, boolean withTagContent, String... tagNames)
content - 文本withTagContent - 是否去掉被包含在标签中的内容tagNames - 要清除的标签public static String removeHtmlAttr(String content, String... attrs)
content - 文本attrs - 属性名(不区分大小写)public static String removeAllHtmlAttr(String content, String... tagNames)
content - 内容tagNames - 指定标签Copyright © 2016. All rights reserved.