类 HtmlUtils
- java.lang.Object
- org.springframework.web.util.HtmlUtils
public abstract class HtmlUtils extends Object
Utility class for HTML escaping. Escapes and unescapes based on the W3C HTML 4.01 recommendation, handling character entity references.Reference: http://www.w3.org/TR/html4/charset.html
For a comprehensive set of String escaping utilities, consider Apache Commons Lang and its StringEscapeUtils class. We are not using that class here to avoid a runtime dependency on Commons Lang just for HTML escaping. Furthermore, Spring's HTML escaping is more flexible and 100% HTML 4.0 compliant.
- 从以下版本开始:
- 01.03.2003
- 作者:
- Juergen Hoeller, Martin Kersten, Craig Andrews
构造器概要
构造器 构造器 说明 HtmlUtils()
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static String
htmlEscape(String input)
Turn special characters into HTML character references.static String
htmlEscape(String input, String encoding)
Turn special characters into HTML character references.static String
htmlEscapeDecimal(String input)
Turn special characters into HTML character references.static String
htmlEscapeDecimal(String input, String encoding)
Turn special characters into HTML character references.static String
htmlEscapeHex(String input)
Turn special characters into HTML character references.static String
htmlEscapeHex(String input, String encoding)
Turn special characters into HTML character references.static String
htmlUnescape(String input)
Turn HTML character references into their plain text UNICODE equivalent.
构造器详细资料
HtmlUtils
public HtmlUtils()
方法详细资料
htmlEscape
public static String htmlEscape(String input)
Turn special characters into HTML character references. Handles complete character set defined in HTML 4.01 recommendation.Escapes all special characters to their corresponding entity reference (e.g.
<
).- 参数:
input
- the (unescaped) input string- 返回:
- the escaped string
htmlEscape
public static String htmlEscape(String input, String encoding)
Turn special characters into HTML character references. Handles complete character set defined in HTML 4.01 recommendation.Escapes all special characters to their corresponding entity reference (e.g.
<
) at least as required by the specified encoding. In other words, if a special character does not have to be escaped for the given encoding, it may not be.- 参数:
input
- the (unescaped) input stringencoding
- the name of a supportedcharset
- 返回:
- the escaped string
- 从以下版本开始:
- 4.1.2
htmlEscapeDecimal
public static String htmlEscapeDecimal(String input)
Turn special characters into HTML character references. Handles complete character set defined in HTML 4.01 recommendation.Escapes all special characters to their corresponding numeric reference in decimal format (Decimal;).
- 参数:
input
- the (unescaped) input string- 返回:
- the escaped string
htmlEscapeDecimal
public static String htmlEscapeDecimal(String input, String encoding)
Turn special characters into HTML character references. Handles complete character set defined in HTML 4.01 recommendation.Escapes all special characters to their corresponding numeric reference in decimal format (Decimal;) at least as required by the specified encoding. In other words, if a special character does not have to be escaped for the given encoding, it may not be.
- 参数:
input
- the (unescaped) input stringencoding
- the name of a supportedcharset
- 返回:
- the escaped string
- 从以下版本开始:
- 4.1.2
htmlEscapeHex
public static String htmlEscapeHex(String input)
Turn special characters into HTML character references. Handles complete character set defined in HTML 4.01 recommendation.Escapes all special characters to their corresponding numeric reference in hex format (Hex;).
- 参数:
input
- the (unescaped) input string- 返回:
- the escaped string
htmlEscapeHex
public static String htmlEscapeHex(String input, String encoding)
Turn special characters into HTML character references. Handles complete character set defined in HTML 4.01 recommendation.Escapes all special characters to their corresponding numeric reference in hex format (Hex;) at least as required by the specified encoding. In other words, if a special character does not have to be escaped for the given encoding, it may not be.
- 参数:
input
- the (unescaped) input stringencoding
- the name of a supportedcharset
- 返回:
- the escaped string
- 从以下版本开始:
- 4.1.2
htmlUnescape
public static String htmlUnescape(String input)
Turn HTML character references into their plain text UNICODE equivalent.Handles complete character set defined in HTML 4.01 recommendation and all reference types (decimal, hex, and entity).
Correctly converts the following formats:
&#Entity; - (Example: &) case sensitive &#Decimal; - (Example: D)
Gracefully handles malformed character references by copying original characters as is when encountered.
&#xHex; - (Example: å) case insensitive- 参数:
input
- the (escaped) input string- 返回:
- the unescaped string