Replace characters with HTML entities in java
问题 I want to replace certain characters with their respective HTML entities in an HTML response inside a filter. Characters include < , > , & . I can't use replaceAll() as it will replace all characters, even those that are part of HTML tags. What is the best approach for doing so? 回答1: From java you may try, Apache Commons Lang (legacy v2) StringEscapeUtils.escapeHtml(). or with commons-lang3: StringEscapeUtils.escapeHtml4(). Please note this also converts à to à & such 回答2: If you're using a