我想在某个过滤器中的HTML响应中替换其各自的HTML实体的某些字符。角色包括 ,> ,& 。我不能使用 replaceAll(),因为它将替换所有字符,甚至是HTML标签的一部分。
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?
推荐答案从java可以尝试,Apache Commons Lang(legacy v2) a href =commons.apache/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html#escapeHtml(java.lang.String) = nofollow noreferrer> StringEscapeUtils.escapeHtml() 。 或与commons-lang3: StringEscapeUtils.escapeHtml4() 。
From java you may try, Apache Commons Lang (legacy v2) StringEscapeUtils.escapeHtml(). or with commons-lang3: StringEscapeUtils.escapeHtml4().
请注意,这也会转换à to & agrave; &这样的
Please note this also converts à to à & such
更多推荐
在Java中用HTML实体替换字符
发布评论